/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 3ms 576.0 KiB
#3 Accepted 1ms 764.0 KiB
#4 Accepted 95ms 1.039 MiB
#5 Accepted 80ms 1.324 MiB
#6 Accepted 95ms 1.184 MiB
#7 Accepted 3ms 532.0 KiB
#8 Accepted 81ms 2.82 MiB
#9 Accepted 85ms 2.812 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]);
            }
        }

        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:27:53
Judged At
2025-08-31 16:27:53
Judged By
Score
100
Total Time
95ms
Peak Memory
2.82 MiB