# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
587929 | jmyszka2007 | Potatoes and fertilizers (LMIO19_bulves) | C++17 | 212 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;
int main() {
int n;
scanf("%d", &n);
vector<int>a(n + 1);
vector<int>b(n + 1);
for(int i = 1; i <= n; i++) {
scanf("%d%d", &a[i], &b[i]);
}
ll ans = 0;
ll d = 0;
priority_queue<ll>q;
for(int i = 1; i <= n; i++) {
d += a[i] - b[i];
ans += abs(d);
if(d < 0) {
q.push(0);
q.push(0);
}
else {
q.push(d);
q.push(d);
}
q.pop();
}
while(!q.empty()) {
ll x = q.top();
q.pop();
ans -= min(x, d);
}
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... |