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>
#define int long long
using namespace std;
int n,a[500001],b[500001],d[500001],res;
priority_queue <int> q;
int32_t main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> n;
for (int i=1;i<=n;i++){
cin >> a[i] >> b[i];
d[i]=d[i-1]+a[i]-b[i];
}
for (int i=1;i<n;i++){
res+=max(-d[i],0LL)+max(d[i]-d[n],0LL);
d[i]=min(max(d[i],0LL),d[n]);
q.push(d[i]);
q.push(d[i]);
res+=q.top()-d[i];
q.pop();
}
cout << res;
}
# | 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... |