#include "candies.h"
#include<bits/stdc++.h>
using namespace std;
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();
if (n <= 2000) {
vector<int> ans(n);
for (int i = 0; i < q; ++i) {
for (int j = l[i]; j <= r[i]; ++j) {
if (v[i] > 0)
ans[j] = min(c[j], ans[j] + v[i]);
else
ans[j] = max(0, ans[j] + v[i]);
}
}
return ans;
}
if (*min_element(v.begin(), v.end()) > 0) {
vector<int64_t> s(n + 1);
vector<int> ans(n);
for (int i = 0; i < q; ++i) {
s[l[i]] += v[i];
s[r[i] + 1] -= v[i];
}
for (int i = 0; i < n; ++i) {
s[i] += (i ? s[i - 1] : 0);
ans[i] = (s[i] <= c[i] ? s[i] : c[i]);
}
return ans;
}
int cur = 0;
for (int i = 0; i < q; ++i) {
if (v[i] > 0)
cur = min(c[0], cur + v[i]);
else
cur = max(0, cur + v[i]);
}
return vector<int>(n, cur);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
420 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
13884 KB |
Output is correct |
2 |
Correct |
67 ms |
12884 KB |
Output is correct |
3 |
Correct |
65 ms |
12788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
124 ms |
8020 KB |
Output is correct |
3 |
Incorrect |
32 ms |
5700 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
336 ms |
7788 KB |
Output is correct |
4 |
Incorrect |
27 ms |
3932 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
420 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
82 ms |
13884 KB |
Output is correct |
7 |
Correct |
67 ms |
12884 KB |
Output is correct |
8 |
Correct |
65 ms |
12788 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
124 ms |
8020 KB |
Output is correct |
11 |
Incorrect |
32 ms |
5700 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |