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 <iostream>
#include <queue>
using namespace std;
const int nmax=500005;
priority_queue<long long> pq;
long long c[nmax];
long long ans;
int n,i,j,a,b;
int main()
{
cin>>n;
for(i=1;i<=n;i++)
{
cin>>a>>b;
long long dif=a-b;
c[i]=(c[i-1]+dif);
}
for(i=1;i<=n;i++)
{
if(c[i]<0) ans-=c[i],c[i]=0;
if(c[i]>c[n]) ans+=(c[i]-c[n]),c[i]=c[n];
}
for(i=1;i<=n;i++)
{
pq.push(c[i]);
if(pq.top()>c[i])
{
pq.push(c[i]);
ans+=1LL*pq.top()-c[i];
pq.pop();
}
}
cout<<ans;
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... |