/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 532.0 KiB
#2 Accepted 5ms 532.0 KiB
#3 Accepted 1ms 320.0 KiB
#4 Accepted 96ms 1.031 MiB
#5 Accepted 71ms 1.145 MiB
#6 Accepted 71ms 1.184 MiB
#7 Accepted 8ms 532.0 KiB
#8 Accepted 82ms 2.812 MiB
#9 Accepted 60ms 2.812 MiB

Code

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

int main() {
    int t;
    cin>>t;
    

    while (t--) {
        int n;  
        cin >> n;

        vector<long long> buyPrices(n);
        vector<long long> sellPrices(n);

        
        for (int i = 0; i < n; i++) {
            cin >> buyPrices[i];
        }

      
        for (int i = 0; i < n; i++) {
            cin >> sellPrices[i];
        }

        vector<long long> maxSellPrice(n);
        maxSellPrice[n - 1] = sellPrices[n - 1];

      
        for (int i = n - 2; i >= 0; i--) {
            if (sellPrices[i] > maxSellPrice[i + 1]) {
                maxSellPrice[i] = sellPrices[i];
            } else {
                maxSellPrice[i] = maxSellPrice[i + 1];
            }
        }

        long long totalProfit = 0;

    
        for (int i = 0; i < n; i++) {
            if (maxSellPrice[i] > buyPrices[i]) {
                totalProfit += maxSellPrice[i] - buyPrices[i];
            }
        }

        cout << totalProfit << "\n";
    }

    return 0;
}
   
            
        
       

Information

Submit By
Type
Submission
Problem
P1228 Business Strategy
Contest
LUCC Presents Intra LU Junior Programming Contest - Replay
Language
C++11 (G++ 13.2.0)
Submit At
2025-09-02 17:33:21
Judged At
2025-09-02 17:33:21
Judged By
Score
100
Total Time
96ms
Peak Memory
2.812 MiB