/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 536.0 KiB
#2 Accepted 2ms 580.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 41ms 1.27 MiB
#5 Accepted 19ms 1.23 MiB
#6 Accepted 19ms 1.234 MiB
#7 Accepted 2ms 532.0 KiB
#8 Accepted 42ms 2.77 MiB
#9 Accepted 17ms 2.77 MiB

Code

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

#define ll long long
#define endl '\n'

long long toNum(string s){
    long long num = 0;
    for(int i = 0 ; i < s.size() ; i++){
        num = (num * 10) + (s[i] - '0');
    }
    return num;
}
const int N = 1e5+3;


void solve(){
    int n;
    cin >> n;

    vector<ll> a(n+1), b(n+1), sufMAX(n+5,0);
    for(int i = 1 ; i <= n ; i++){
        cin >> a[i];
    }
    for(int i = 1 ; i <= n ; i++){
        cin >> b[i];
    }
    for(int i = n  ; i > 0 ; i--){
        //cout << b[i] << " " << sufMAX[i+1] << endl;
        sufMAX[i] = (sufMAX[i+1] > b[i] ? sufMAX[i+1] : b[i]);
    }
    
    ll prof = 0;
    for(int  i = 1 ; i <= n ; i++){
        if(a[i] < sufMAX[i])    prof += (sufMAX[i] - a[i]);
    }
    cout << prof << endl;
}

int main(){
    ios_base::sync_with_stdio(0), cin.tie(0);
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

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:49:00
Judged At
2025-09-02 16:49:00
Judged By
Score
100
Total Time
42ms
Peak Memory
2.77 MiB