# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
295720 | RezwanArefin01 | Potatoes and fertilizers (LMIO19_bulves) | C++17 | 232 ms | 15208 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;
typedef pair<int, int> ii;
const int N = 5e5 + 5;
int n;
ll p[N];
int main() {
int n;
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
int a, b;
scanf("%d %d", &a, &b);
p[i] = p[i - 1] + a - b;
}
ll ans = 0;
priority_queue<ll> Q;
for(int i = 1; i <= n; ++i) {
if(p[i] < 0) ans -= p[i], p[i] = 0;
if(p[i] > p[n]) ans += p[i] - p[n], p[i] = p[n];
Q.push(p[i]);
Q.push(p[i]);
ans += Q.top() - p[i];
Q.pop();
}
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... |