#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> distribute_candies(
vector<int> c, vector<int> l,
vector<int> r, vector<int> v
) {
int n = c.size();
int q = v.size();
if (q <= 2000 && n <= 2000) {
vector<int> s(n);
for (int i = 0; i < q; i++) {
for (int j = l[i]; j <= r[i]; j++) {
s[j] = max(min(s[j] + v[i], c[j]), 0);
}
}
return s;
}
bool pos = true;
for (int i = 0; i < n; i++) {
if (c[i] < 0) {
pos = false;
break;
}
}
if (pos) {
// difference array
vector<int> d(n + 1);
for (int i = 0; i < q; i++) {
d[l[i]] += v[i];
d[r[i] + 1] -= v[i];
}
vector<int> s(n);
s[0] = d[0];
for (int i = 1; i < n; i++) {
s[i] = min(s[i - 1] + d[i], c[i]);
}
return s;
}
vector<int> s(n, 0);
return s;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
82 ms |
13020 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
35 ms |
8144 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
436 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
31 ms |
7652 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Incorrect |
82 ms |
13020 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |