# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
200104 | SamAnd | Potatoes and fertilizers (LMIO19_bulves) | C++17 | 257 ms | 15332 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;
const int N = 500005;
int n;
long long a[N];
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
{
scanf("%lld", &a[i]);
int x;
scanf("%d", &x);
a[i] -= x;
a[i] += a[i - 1];
}
long long ans = 0;
for (int i = 1; i <= n; ++i)
{
if (a[i] < 0)
{
ans += (-a[i]);
a[i] = 0;
}
if (a[i] > a[n])
{
ans += (a[i] - a[n]);
a[i] = a[n];
}
}
priority_queue<long long> q;
q.push(a[1]);
for (int i = 2; i <= n; ++i)
{
q.push(a[i]);
if (a[i] < q.top())
{
ans += (q.top() - a[i]);
q.pop();
q.push(a[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... |