| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 615480 | rsjw | Potatoes and fertilizers (LMIO19_bulves) | C++17 | 1 ms | 336 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;
#define int long long
struct Function {
multiset<int> s;
int k, p;
Function(int a, int b) { k = a, p = b; }
void reset(int a, int b) { s.clear(), k = a, p = b; }
void prefix() {
if (k <= 0)
return;
if (s.size() < k)
assert(0);
auto it = s.end();
int c = k;
while (c--) {
it--;
k--, p += *it;
s.erase(it);
}
}
void merge(Function x) {
for (auto ele : x.s)
s.insert(ele);
k += x.k, p += x.p;
}
};
int A[500010], B[500010];
void get() {
int n, i, x;
cin >> n;
for (i = 1; i <= n; i++)
cin >> A[i] >> B[i], A[i] += A[i - 1], B[i] += B[i - 1];
Function a(0, 0);
Function h(0, 0);
for (i = 1; i < n; i++) {
x = A[i] - B[i];
h.reset(1, -x), h.s.insert(x), h.s.insert(x);
a.merge(h);
a.prefix();
}
cout << a.p;
return;
}
signed main() {
ios::sync_with_stdio(false);
cout.tie(NULL);
int T;
T = 1;
while (T--)
get();
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... | ||||
