# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
436532 | VladaMG98 | Distributing Candies (IOI21_candies) | C++17 | 144 ms | 12004 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 "candies.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
typedef long long ll;
const ll INF = 1e18;
ll a[MAXN];
ll suf_max[MAXN], suf_min[MAXN];
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
int q = (int)c.size();
int n = (int)l.size();
vector<int> answer(q);
a[1] = INF;
a[2] = 0;
for (int i = 3; i <= n + 2; i++) {
a[i] = a[i - 1] + v[i - 3];
}
n += 2;
suf_min[n] = suf_max[n] = a[n];
for (int i = n - 1; i >= 1; i--) {
suf_min[i] = min(suf_min[i + 1], a[i]);
suf_max[i] = max(suf_max[i + 1], a[i]);
}
// for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl;
for (int q_i = 0; q_i < q; q_i++) {
int C = c[q_i], ans;
ll cur_mx = a[n], cur_mn = a[n];
int lo = 1, hi = n;
while (lo <= hi) {
int md = (lo + hi) / 2;
if (suf_max[md] - suf_min[md] >= C) {
ans = md;
lo = md + 1;
} else {
hi = md - 1;
}
}
if (a[ans] == suf_max[ans]) answer[q_i] = a[n] - suf_min[ans];
else answer[q_i] = C - (suf_max[ans] - a[n]);
}
return answer;
}
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... |