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;
long long c[500001], ans = 0;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
long long a, b;
cin >> a >> b;
c[i] = c[i - 1] + a - b;
}
priority_queue<long long> pq;
for (int i = 1; i <= n; i++) {
if (c[i] > c[n]) {
ans += c[i] - c[n];
c[i] = c[n];
} else if (c[i] < 0) {
ans -= c[i];
c[i] = 0;
}
pq.push(c[i]); pq.push(c[i]);
ans += pq.top() - c[i];
pq.pop();
}
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... |