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;
vector<long long>s(n);
for(auto &x: s){
int a,b;
cin>>a>>b;
x=a-b;
}
partial_sum(s.begin(),s.end(),s.begin());
long long t=0;
priority_queue<long long,vector<long long>,greater<long long>>q;
for(int i=0;i<n+2;i++){
q.push(1ll*0);
}
for(auto w : s){
q.pop();
t+=max(-w-q.top(), 0LL);
q.push(-w);
q.push(-w);
}
long long ctr=0;
while(q.top()!=-s.back()){
auto x=q.top();
q.pop();
t+=ctr*(q.top()-x);
ctr++;
}
cout<<t;
}
# | 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... |