Accepted
Code
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
vector<long long> a(n), b(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
long long profit = 0;
long long maxSell = 0;
for (int i = n - 1; i >= 0; i--) {
maxSell = max(maxSell, b[i]);
if (maxSell > a[i]) {
profit += (maxSell - a[i]);
}
}
cout << profit << "\n";
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1228 Business Strategy
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2025-09-12 07:03:18
- Judged At
- 2025-09-12 07:03:18
- Judged By
- Score
- 100
- Total Time
- 38ms
- Peak Memory
- 2.062 MiB