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 ll long long
const int nx=5e5+5;
ll n, a[nx], b[nx], d[nx], res;
priority_queue<ll> pq;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>a[i]>>b[i], d[i]=d[i-1]+(a[i]-b[i]);
for (int i=1; i<n; i++)
{
if (d[i]<0) res-=d[i], d[i]=0;
else if (d[i]>d[n]) res+=d[i]-d[n];
//pq.push(d[i]);
//pq.push(d[i]);
//pq.pop();
}
cout<<res<<'\n';
//while (!pq.empty()) cout<<pq.top()<<' ', pq.pop();
}
# | 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... |