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>
//#include "bits_stdc++.h"
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
int main()
{
ll ans = 0;
priority_queue<ll> pq;
ll n, a, b;
cin >> n;
ll dif[n+1], ps[n+1];
ps[0]=0;
for (ll i=1; i<=n; ++i)
{
cin >> a >> b;
dif[i] = a-b;
ps[i]= ps[i-1] + dif[i];
ans +=abs(ps[i]);
pq.push(max(0LL, ps[i]));
pq.push(max(0LL, ps[i]));
pq.pop();
}
for (ll i=0; i<n; ++i) {ans-=min(pq.top(), ps[n]); pq.pop();}
cout << ans << endl;
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... |