/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 2ms 536.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 19ms 940.0 KiB
#5 Accepted 25ms 788.0 KiB
#6 Accepted 21ms 788.0 KiB
#7 Accepted 2ms 532.0 KiB
#8 Accepted 17ms 1.559 MiB
#9 Accepted 18ms 1.555 MiB

Code

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

typedef long long ll;
typedef double dl;

#define endl "\n"
#define vi vector<int>
#define mii map<int,int>
#define mci map<char,int>
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;

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

    int buy[n+10], sell[n+10];

    for(int i = 0; i < n; i++){
        cin >> buy[i];
       // ar2[i] = ar[i];
        //mp[ar[i]]++;
    }
    for(int i = 0; i < n; i++){
        cin >> sell[i];
    }

    int mx[n+10];
    mx[n-1] = sell[n-1];

    for(int i = n-2; i>=0; i--){
        mx[i] = max(mx[i+1] , sell[i] );
    }

    ll ans = 0;
    for(int i  = 0; i < n; i++){
        ll tt = mx[i] - buy[i];

        if(tt > 0)    ans+=tt;
    }

    cout << ans << endl;

}

int main()
{
    optimize();

    int t;
    cin >> t;

    while(t--)  solve();

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1228 Business Strategy
Contest
LUCC Presents Kick & Code Intra LU Programming Contest
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-01 06:45:19
Judged At
2025-09-01 06:45:19
Judged By
Score
100
Total Time
25ms
Peak Memory
1.559 MiB