# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1166834 | tamyte | Potatoes and fertilizers (LMIO19_bulves) | C++20 | 77 ms | 10312 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
ll calc(vector<int> a, vector<int> b) {
ll res = 0;
stack<pair<int, int>> left, right;
for (int i = n - 1; i >= 0; --i) {
if (a[i] > 0) {
right.push({a[i], i});
}
}
for (int i = 0; i < n; ++i) {
while (right.size() && right.top().second <= i) {
left.push({right.top()});
right.pop();
}
while (b[i] > 0) {
if (left.size()) {
int need = min(b[i], left.top().first);
b[i] -= need;
left.top().first -= need;
int d = abs(i - left.top().second);
res += 1LL * d * need;
} else {
int need = min(b[i], right.top().first);
b[i] -= need;
right.top().first -= need;
# | 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... |