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;
int a[n], b[n];
long long res=0;
long long d=0, dd=0;
priority_queue<long long> pq;
for(int i = 0;i<n;i++) {
cin >> a[i] >> b[i];
dd+=a[i]-b[i];
}
for(int i = 0;i<n;i++) {
d+=a[i]-b[i];
long long c=d;
if(c<0) {
res-=c;
c=0;
}
if(c>dd) {
res+=c-dd;
c=dd;
}
// cerr << c << " " << d << endl;
pq.push(c);
if(pq.top()!=c) {
res+=pq.top()-c;
pq.pop();
pq.push(c);
}
}
cout << res << "\n";
}
# | 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... |