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;
int v[500100];
long long ans = 0;
priority_queue<int> heap;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n;
for (int i = 1; i <= n; i++) {
int a, b; cin >> a >> b;
v[i] = a-b + v[i-1];
}
for (int i = 1; i <= n; i++) {
if (v[i] > v[n]) {ans += v[i]-v[n]; v[i] = v[n];} // v[n] can't be changed
if (v[i] < 0) {ans += 0-v[i]; v[i] = 0;} // v[i] >= 0
heap.push(v[i]);
heap.push(v[i]);
ans += heap.top() - v[i];
heap.pop();
}
cout << ans << endl;
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... |