#include <bits/stdc++.h>
using namespace std;
#include "candies.h"
#define ll long long
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v){
int N = c.size(), Q = v.size();
vector<int> ans(N, 0);
if(N <= 2000 && Q <= 2000){
for(int i = 0; i < Q; i++){
for(int j = l[i]; j <= r[i]; j++){
if(v[i] < 0) ans[j] = max(0, ans[j] + v[i]);
else if(v[i] > 0) ans[j] = min(c[j], ans[j] + v[i]);
}
}
}else{
vector<ll> pref(N + 1, 0);
for(int i = 0; i < Q; i++){
pref[l[i]] += v[i];
pref[r[i] + 1] -= v[i];
}
for(int i = 1; i < N; i++) pref[i] += pref[i - 1];
for(int i = 0; i < N; i++){
if(pref[i] > (ll) c[i]) ans[i] = c[i];
else ans[i] = pref[i];
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
432 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
3 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
8884 KB |
Output is correct |
2 |
Correct |
116 ms |
8932 KB |
Output is correct |
3 |
Correct |
114 ms |
8880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
62 ms |
4960 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
59 ms |
4948 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
432 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
3 ms |
332 KB |
Output is correct |
6 |
Correct |
127 ms |
8884 KB |
Output is correct |
7 |
Correct |
116 ms |
8932 KB |
Output is correct |
8 |
Correct |
114 ms |
8880 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Incorrect |
62 ms |
4960 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |