#include "candies.h"
#include <vector>
#include <algorithm>
using namespace std;
struct Move {
long long o;
long long n;
long long c;
};
vector<Move> V;
long long cnt;
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
cnt = 0; V.clear();
int n = (int)c.size(), q = (int)v.size();
long long globalMin = 0, globalMax = 0;
vector<int> s(n);
for (int t = 0; t < q; t++) {
long long tmp_curr = v[t];
if (tmp_curr > 0) {
long long curr = tmp_curr;
while (!V.empty()) {
if (V.back().n > V.back().o) {
if (V.back().o < cnt) {
tmp_curr = cnt + tmp_curr - V.back().o;
cnt = V.back().o;
}
V.pop_back();
} else if (V.back().c <= curr) V.pop_back();
else break;
}
} else {
long long curr = -tmp_curr;
while (!V.empty()) {
if (V.back().n < V.back().o) {
if (V.back().o > cnt) {
tmp_curr = cnt + tmp_curr - V.back().o;
cnt = V.back().o;
}
V.pop_back();
} else if (V.back().c <= curr) V.pop_back();
else break;
}
}
V.push_back(Move{ cnt, cnt + tmp_curr, tmp_curr > 0 ? tmp_curr : -tmp_curr });
cnt += tmp_curr;
globalMin = min(globalMin, cnt), globalMax = max(globalMax, cnt);
}
//for (auto &i: V) printf("%lld %lld %d\n", i.o, i.n, i.c);
reverse(V.begin(), V.end());
for (int i = 0; i < n; i++) {
long long l = min(V.back().o, V.back().n), r = max(V.back().o, V.back().n);
if (V.back().c > c[i]) {
Move x = *(upper_bound(V.rbegin(), V.rend(), Move{ 0LL, 0LL, c[i] }, [](const Move &a, const Move &b) {
return a.c < b.c;
}) - 1);
if (x.o > x.n) l = x.n, r = l + c[i];
else r = x.n, l = r - c[i];
//printf("%lld %lld %d\n", x.o, x.n, x.c);
}
//printf("! %lld %lld\n", l, r);
if (l < 0) s[i] = cnt - l;
else if (r > c[i]) s[i] = cnt - r + c[i];
else s[i] = cnt;
}
return s;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
137 ms |
7256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |