#include "candies.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(), x.end()
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> a(n);
if(n<=2000 && q<=2000){
for(int t=0;t<q;t++){
for(int i=l[t];i<=r[t];i++){
a[i]+=v[t];
a[i]=min(c[i],a[i]);
a[i]=max(a[i],0);
}
}
}
else{
vector<long long> pref(n);
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++)
a[i]=min(pref[i],(long long)c[i]);
}
return a;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
8812 KB |
Output is correct |
2 |
Correct |
78 ms |
12884 KB |
Output is correct |
3 |
Correct |
81 ms |
12788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
52 ms |
4952 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 |
41 ms |
4960 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 |
0 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 |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
81 ms |
8812 KB |
Output is correct |
7 |
Correct |
78 ms |
12884 KB |
Output is correct |
8 |
Correct |
81 ms |
12788 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Incorrect |
52 ms |
4952 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |