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>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
const ll NMAX = 500001;
const ll VMAX = 1000001;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 447;
const ll nr_of_bits = 21;
int n;
ll v[NMAX], a, b;
int main() {
//ifstream cin("niceset.in");
//ofstream cout("niceset.out");
int i;
cin >> n;
for(i = 1; i <= n; i++){
cin >> a >> b;
a -= b;
v[i] = a;
v[i] += v[i - 1];
}
ll sol = 0;
priority_queue <ll> pq;
for(i = 1; i <= n; i++){
if(v[i] < 0){
sol += -v[i];
v[i] = 0;
}
if(v[i] > v[n]){
sol += (v[i] - v[n]);
v[i] = v[n];
}
pq.push(v[i]);
pq.push(v[i]);
sol += (v[n] - v[i]);
sol -= (v[n] - pq.top());
pq.pop();
}
cout << sol;
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... |