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 main() {
int n;
cin >> n;
vector <long long> pre (n + 1);
for(int i = 1; i <= n; i++) {
int a, b;
cin >> a >> b;
pre[i] = pre[i - 1] + a - b;
}
priority_queue <long long> Q;
long long base = 0;
for(int i = 1; i <= n; i++) {
if(pre[i] < 0) {
base += -pre[i];
pre[i] = 0;
}
if(pre[i] > pre[n]) {
base += pre[i] - pre[n];
pre[i] = pre[n];
}
Q.push(pre[i]);
Q.push(pre[i]);
if(pre[i] < Q.top()) {
base += Q.top() - pre[i];
}
Q.pop();
}
cout << base << 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... |