/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 644.0 KiB
#3 Accepted 2ms 532.0 KiB
#4 Accepted 38ms 1.02 MiB
#5 Accepted 18ms 1020.0 KiB
#6 Accepted 23ms 948.0 KiB
#7 Accepted 2ms 448.0 KiB
#8 Accepted 18ms 2.062 MiB
#9 Accepted 16ms 2.062 MiB

Code

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while (T--) {
        int n;
        cin >> n;
        vector<long long> a(n), b(n);

        for (int i = 0; i < n; i++) cin >> a[i];
        for (int i = 0; i < n; i++) cin >> b[i];

        long long profit = 0;
        long long maxSell = 0; 

        
        for (int i = n - 1; i >= 0; i--) {
            maxSell = max(maxSell, b[i]); 
            if (maxSell > a[i]) {
                profit += (maxSell - a[i]); 
            }
        }

        cout << profit << "\n";
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1228 Business Strategy
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-12 07:03:18
Judged At
2025-09-12 07:03:18
Judged By
Score
100
Total Time
38ms
Peak Memory
2.062 MiB