#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 |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |