# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
329076 | Nirjhor | Potatoes and fertilizers (LMIO19_bulves) | C++17 | 196 ms | 19272 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;
typedef long long ll;
const int N = 500010;
priority_queue <ll> pq;
int n; ll a[N], b[N], steady;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%lld %lld", a + i, b + i);
a[i] -= b[i], a[i] += a[i - 1];
}
ll extra = 0;
for (int i = 1; i <= n; ++i) {
if (a[i] < 0) extra -= a[i], a[i] = 0;
if (a[i] > a[n]) extra += a[i] - a[n], a[i] = a[n];
pq.emplace(a[i]); pq.emplace(a[i]);
steady += pq.top() - a[i]; pq.pop();
}
steady += extra;
cout << steady << '\n';
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... |