# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
236942 | PeppaPig | Potatoes and fertilizers (LMIO19_bulves) | C++14 | 230 ms | 18780 KiB |
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 long long long
using namespace std;
const int N = 5e5 + 5;
int n;
long a[N], b[N], c[N], ans;
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%lld %lld", a + i, b + i);
c[i] = c[i - 1] + a[i] - b[i];
}
priority_queue<long> Q;
for(int i = 1; i <= n; i++) {
if(c[i] > c[n]) ans += c[i] - c[n], c[i] = c[n];
else if(c[i] < 0) ans -= c[i], c[i] = 0;
Q.emplace(c[i]);
if(c[i] < Q.top()) {
ans += Q.top() - c[i];
Q.pop(), Q.emplace(c[i]);
}
}
printf("%lld\n", ans);
return 0;
}
Compilation message (stderr)
# | 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... |