/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 3ms 532.0 KiB
#3 Accepted 1ms 344.0 KiB
#4 Accepted 72ms 1.027 MiB
#5 Accepted 72ms 1.199 MiB
#6 Accepted 72ms 1.184 MiB
#7 Accepted 3ms 532.0 KiB
#8 Accepted 55ms 2.809 MiB
#9 Accepted 57ms 2.816 MiB

Code

#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<ll> buy(n), sell(n);
        for (int i = 0; i < n; i++) {
            cin >> buy[i];
        }
        for (int i = 0; i < n; i++) {
            cin >> sell[i];
        }
        vector<ll> sufMax(n);
        sufMax[n - 1] = sell[n - 1];
        for (int i = n - 2; i >= 0; i--) {
            sufMax[i] = max(sell[i], sufMax[i + 1]);
        }
        ll profit = 0;
        for (int i = 0; i < n; i++) {
            if (sufMax[i] > buy[i]) {
                profit += (sufMax[i] - buy[i]);
            }
        }
        ll y = 0;
        for (int i = 0; i < n; i++){
          for (int j = 0; j < n; j++){
            y++;
          }
        }
        cout << profit << "  \n";
    }
}

Information

Submit By
Type
Submission
Problem
P1228 Business Strategy
Contest
Testing - Intra LU Programming contest 25
Language
C++17 (G++ 13.2.0)
Submit At
2025-08-31 16:29:37
Judged At
2025-08-31 16:29:37
Judged By
Score
100
Total Time
72ms
Peak Memory
2.816 MiB