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;
const int N = (int)5e5;
int n, a[N], b[N];
long long d[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for(int i = 0;i < n;i ++) {
cin >> a[i] >> b[i];
d[i] = a[i]-b[i] + (i!=1?d[i-1]:0);
}
priority_queue<int> pq;
pq.push(d[0]);
long long ans = 0;
for(int i = 1;i < n;i ++) {
pq.push(d[i]);
pq.push(d[i]);
ans += pq.top()-d[i];
pq.pop();
}
cout << ans << '\n';
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... |