# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
587928 | jmyszka2007 | Potatoes and fertilizers (LMIO19_bulves) | C++17 | 15 ms | 1416 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;
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]);
}
int ans = 0;
int d = 0;
priority_queue<int>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()) {
int x = q.top();
q.pop();
ans -= min(x, d);
}
printf("%d\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... |