#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N, Q;
vector<int> a;
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
std::vector<int> r, std::vector<int> v) {
N = c.size(), Q = l.size();
a.resize(N);
if(N <= 2000 && Q <= 2000){
for(int i = 0; i < Q; i++){
for(int j = l[i]; j <= r[i]; j++){
a[j] += v[i];
a[j] = min(a[j], c[j]);
a[j] = max(a[j], 0);
}
}
return a;
} else {
vector<ll> s(N + 1);
for(int i = 0; i < Q; i++){
s[l[i]] += v[i];
s[r[i] + 1] -= v[i];
}
for(int i = 1; i < N; i++){
s[i] += s[i - 1];
}
for(int i = 0; i < N; i++){
a[i] = min(s[i], (ll)c[i]);
}
return a;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
9696 KB |
Output is correct |
2 |
Correct |
97 ms |
13772 KB |
Output is correct |
3 |
Correct |
99 ms |
13612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
53 ms |
4956 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
49 ms |
4968 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Correct |
101 ms |
9696 KB |
Output is correct |
7 |
Correct |
97 ms |
13772 KB |
Output is correct |
8 |
Correct |
99 ms |
13612 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Incorrect |
53 ms |
4956 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |