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;
#define ar array
typedef long long ll;
#define int ll
const int N = 5e5 + 5;
int a[N], b[N];
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
int res = 0;
for(int i=1;i<=n;i++){
cin >> a[i] >> b[i];
a[i] -= b[i];
a[i] += a[i-1];
}
int mx = a[n];
assert(0 <= mx);
for(int i=1;i<=n;i++){
if(a[i] < 0){
res -= a[i];
a[i] = 0;
}
if(a[i] > mx){
res += (a[i] - mx);
a[i] = mx;
}
}
priority_queue<int> q;
for(int i=1;i<=n;i++){
q.push(a[i]);
if(a[i] < q.top()){
res += (q.top() - a[i]);
q.pop(); q.push(a[i]);
}
}
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... |