# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
204673 | nhho | Potatoes and fertilizers (LMIO19_bulves) | C++14 | 220 ms | 15204 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>
using namespace std;
int n;
long long ans, x[500001];
priority_queue<long long> q;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int ta, tb;
scanf("%d%d", &ta, &tb);
x[i + 1] = x[i] + ta - tb;
}
for (int i = 1; i < n; i++) {
if (x[i] < 0) {
ans -= x[i];
x[i] = 0;
} else if (x[i] > x[n]) {
ans += x[i] - x[n];
x[i] = x[n];
}
q.push(x[i]);
ans += q.top() - x[i];
q.push(x[i]);
q.pop();
}
printf("%lld\n", ans);
}
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... |