/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 340.0 KiB
#2 Accepted 2ms 532.0 KiB
#3 Accepted 1ms 324.0 KiB
#4 Accepted 19ms 1.289 MiB
#5 Accepted 18ms 1.066 MiB
#6 Accepted 18ms 1.062 MiB
#7 Accepted 2ms 536.0 KiB
#8 Accepted 18ms 2.824 MiB
#9 Accepted 18ms 2.828 MiB

Code

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

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int tc; cin >> tc;

    test:
    while (tc--) {
        ll n; cin >> n;
        
        ll a[n+1], b[n+1];
        for (ll i = 1; i <= n; i++) cin >> a[i];
        for (ll i = 1; i <= n; i++) cin >> b[i];

        ll suffMx[n+2] = {0};
        for (ll i = n; i >= 1; i--) suffMx[i] = max(suffMx[i+1], b[i]);
        
        ll ans = 0;
        for (ll i = 1; i <= n; i++) ans += max(0LL, suffMx[i] - a[i]);
        cout << ans << "\n";
    }
}

Information

Submit By
Type
Submission
Problem
P1228 Business Strategy
Contest
LUCC Presents Intra LU Junior Programming Contest - Replay
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-02 16:30:47
Judged At
2025-09-02 16:30:47
Judged By
Score
100
Total Time
19ms
Peak Memory
2.828 MiB