#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
int n = sz(c), q = sz(l);
vector<int> ans(n);
if(n <= 2000 and q <= 2000) {
for(int Q = 0; Q < q; Q++) {
for(int i = l[Q]; i <= r[Q]; i++)
ans[i] = min(max(0, ans[i] + v[Q]), c[i]);
}
}
else {
vector<ll> p(n+1);
for(int Q = 0; Q < q; Q++) {
p[l[Q]] += v[Q];
p[r[Q]+1] -= v[Q];
}
for(int i = 0; i < n; i++) {
if(i > 0) p[i] += p[i-1];
ans[i] = min((ll)c[i], p[i]);
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
8908 KB |
Output is correct |
2 |
Correct |
52 ms |
9052 KB |
Output is correct |
3 |
Correct |
51 ms |
9052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
27 ms |
5104 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
25 ms |
4968 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
61 ms |
8908 KB |
Output is correct |
7 |
Correct |
52 ms |
9052 KB |
Output is correct |
8 |
Correct |
51 ms |
9052 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Incorrect |
27 ms |
5104 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |