| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1363678 | vjudge1 | Potatoes and fertilizers (LMIO19_bulves) | C++20 | 81 ms | 8556 KiB |
/*
address:https://vjudge.net/problem/OJUZ-LMIO19_bulves
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5e5 + 5;
int n;
LL a[N];
LL ans;
priority_queue<LL>q;
int main() {
scanf("%d", &n);
for (int i = 1;i <= n;++i) {
int x, y;scanf("%d%d", &x, &y);
a[i] = a[i - 1] + x - y;
}
for (int i = 0;i <= n;++i) {
LL x = min(a[n], max(0ll, a[i]));
ans += abs(x - a[i]);
q.push(x);
if (x < q.top()) {
ans += q.top() - x;
q.push(x);
q.pop();
}
}
printf("%lld", ans);
return 0;
}Compilation message (stderr)
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
