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 n;
long long lazy, vc, slope;
priority_queue<long long, vector<long long>, greater<long long> > pq;
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> n;
pq.push(0);
for(int i = 1; i <= n; i++){
int a, b;
cin >> a >> b;
int d = a - b;
lazy += d;
if(pq.top() + lazy < d){
vc += d - (pq.top() + lazy);
if(pq.top() != 0) pq.pop();
if(d <= lazy){
pq.push(d - lazy);
pq.push(d - lazy);
}
} else {
pq.push(d - lazy);
}
}
long long cur = pq.top() + lazy;
slope = 0;
while(!pq.empty()){
long long nxt = pq.top() + lazy; pq.pop();
nxt = min(nxt, 0LL);
vc += (nxt - cur) * slope;
slope++; cur = nxt;
}
if(cur != 0) vc += -cur * slope;
cout << vc << "\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... |