# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
331335 | Nson | Potatoes and fertilizers (LMIO19_bulves) | C++14 | 19 ms | 1132 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;
using ll = long long;
int main() {
int n;
scanf("%d", &n);
multiset<ll> s;
ll m = 0, b = 0;
s.insert(0);
auto smooth = [&]() {
while(!s.empty() and m > 0 and *prev(s.end()) > 0) {
m--;
b += *prev(s.end());
s.erase(prev(s.end()));
}
};
ll d = 0;
for(int i = 0; i < n; i++) {
int aa, bb;
scanf("%d %d", &aa, &bb);
aa -= bb;
d += aa;
smooth();
s.insert(d);
s.insert(d);
b -= d;
m += 1;
while(!s.empty() and *s.begin() < 0) s.erase(s.begin());
}
smooth();
printf("%lld\n", d * m + b);
}
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... |