#include "candies.h"
#include <algorithm>
#include <vector>
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
std::vector<int> r, std::vector<int> v) {
int n = c.size(), q = v.size();
std::vector<std::vector<std::pair<int, int>>> queriesL(n), queriesR(n);
for (int i = 0; i < q; ++i) {
queriesL[l[i]].emplace_back(i, v[i]);
queriesR[r[i]].emplace_back(i, v[i]);
}
std::vector<int> s(n), vals(q);
for (int i = 0; i < n; ++i) {
for (auto [idx, val] : queriesL[i]) {
vals[idx] = -val;
}
int mini = 0, maxi = 0, sum = 0, idx = 0;
for (int j = q - 1; j >= 0; --j) {
sum += vals[j];
mini = std::min(mini, sum);
maxi = std::max(maxi, sum);
if (maxi - mini > c[i]) {
idx = j;
break;
}
}
if (maxi - mini <= c[i]) {
s[i] = -mini;
} else {
if (vals[idx] < 0) {
s[i] = c[i] - maxi;
} else {
s[i] = -mini;
}
}
for (auto [idx, val] : queriesR[i]) {
vals[idx] = 0;
}
}
return s;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
424 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1281 ms |
30312 KB |
Output is correct |
2 |
Execution timed out |
5042 ms |
29444 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
517 ms |
14452 KB |
Output is correct |
3 |
Correct |
520 ms |
14400 KB |
Output is correct |
4 |
Execution timed out |
5037 ms |
31348 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
124 ms |
11556 KB |
Output is correct |
4 |
Correct |
183 ms |
13296 KB |
Output is correct |
5 |
Execution timed out |
5039 ms |
24124 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
424 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
556 KB |
Output is correct |
6 |
Correct |
1281 ms |
30312 KB |
Output is correct |
7 |
Execution timed out |
5042 ms |
29444 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |