Accepted
Code
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<ll> 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<ll> sufMax(n);
sufMax[n - 1] = sell[n - 1];
for (int i = n - 2; i >= 0; i--) {
sufMax[i] = max(sell[i], sufMax[i + 1]);
}
ll profit = 0;
for (int i = 0; i < n; i++) {
if (sufMax[i] > buy[i]) {
profit += (sufMax[i] - buy[i]);
}
}
ll y = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
y++;
}
}
cout << profit << " \n";
}
}
Information
- Submit By
- Type
- Submission
- Problem
- P1228 Business Strategy
- Contest
- Testing - Intra LU Programming contest 25
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2025-08-31 16:29:37
- Judged At
- 2025-08-31 16:29:37
- Judged By
- Score
- 100
- Total Time
- 72ms
- Peak Memory
- 2.816 MiB