This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int NM = 5e5;
int N, a[NM+5], b[NM+5], ans = 0;
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N;
for (int i = 1; i <= N; i++){
cin >> a[i] >> b[i];
}
for (int i = 2; i <= N; i++)
if (a[i-1] > b[i-1]){
ans += a[i-1]-b[i-1];
a[i] += a[i-1]-b[i-1];
a[i-1] = b[i-1];
}
for (int i = N-1; i >= 1; i--)
if (a[i+1] > b[i+1]){
ans += a[i+1]-b[i+1];
a[i] += a[i+1]-b[i+1];
a[i+1] = b[i+1];
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |