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;
long long int c[500'009];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n,a,b,odp = 0;
cin >> n;
c[0] = 0;
for (int x=1;x<=n;x++){
cin >> a >> b;
c[x] = a-b;
//c[x] -= x;
c[x] += c[x-1];
}
priority_queue<int> slope;
slope.push(0);
for (int x=1;x<=n;x++){
if (c[x] < 0){
odp += 0 - c[x];
c[x] = 0;
}
if (c[x] > c[n]){
odp += c[x] - c[n];
c[x] = c[n];
}
slope.push(c[x]);
if (c[x] < slope.top()){
odp += slope.top() - c[x];
slope.pop();
slope.push(c[x]);
}
}
cout << odp << "\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... |