/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 484.0 KiB
#3 Accepted 1ms 764.0 KiB
#4 Accepted 30ms 1.27 MiB
#5 Accepted 31ms 1.066 MiB
#6 Accepted 33ms 1.293 MiB
#7 Accepted 2ms 532.0 KiB
#8 Accepted 18ms 2.84 MiB
#9 Accepted 17ms 2.77 MiB

Code

#include <bits/stdc++.h>
#define int long long
using namespace std;
/*
        OBSERVATIONS:

    FOR TODAY SELLING PRICE IF I SELL TODAY THEN ALL THE PRICES <=SELLING PRICE [I] WILL BE USED
    WHAT ABOUT REMAINING?
    THAT DOES NOT FEEL LIKE IT WILL WORK

    DP[0]=0 I DO NOTHING ON DAY
    AT EVERY INDEX I WILL BUY THIS STOCK ONLY IF I CAN SELL THIS?
    IF THERE IS SOME J
*/
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<int> 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<int> suffix(n, 0);
        suffix[n - 1] = sell[n - 1];
        for (int i = n - 2; i >= 0; i--)
        {
            suffix[i] = sell[i];
            suffix[i] = max(suffix[i], suffix[i + 1]);
        }
        int res = 0;
        for (int i = 0; i < n; i++)
            res += max(0LL, suffix[i] - buy[i]);
        cout << res << endl;
    }
    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:45:59
Judged At
2025-09-02 16:45:59
Judged By
Score
100
Total Time
33ms
Peak Memory
2.84 MiB