#include "candies.h"
#include <vector>
#include <algorithm>
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l, std::vector<int> r, std::vector<int> v) {
int n=c.size();
int q=l.size();
std::vector<int> s(n,0);
// bool flag=true;
// for(int i=0;i<q;i++){
// if(v[i]<0){
// flag=false;
// break;
// }
// }
// if(flag==false){
for(int j=0;j<q;j++){
for(int i=l[j];i<=r[j];i++){
if(v[j]>0){
if(c[i]>(s[i]+v[j])) s[i]+=v[j];
else s[i]=c[i];
}else{
if((s[i]+v[j])<0) s[i]=0;
else s[i]+=v[j];
}
}
}
// }else{
// s.push_back(0);
// int h=0,k=0;
// for(int j=0;j<q;j++){
// h=l[j];
// s[h]+=v[j];
// k=r[j]+1;
// s[k]-=v[j];
// }
// for(int i=1;i<=n;i++){
// s[i]+=s[i-1];
// }
// s.pop_back();
// for(int i=0;i<n;i++){
// if(s[i]>c[i]){
// s[i]=c[i];
// }
// }
// }
return s;
}
# |
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 |
2 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5093 ms |
7252 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
171 ms |
5768 KB |
Output is correct |
3 |
Correct |
161 ms |
4572 KB |
Output is correct |
4 |
Execution timed out |
5059 ms |
8020 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
260 KB |
Output is correct |
3 |
Correct |
394 ms |
5776 KB |
Output is correct |
4 |
Correct |
395 ms |
3552 KB |
Output is correct |
5 |
Execution timed out |
5090 ms |
7988 KB |
Time limit exceeded |
6 |
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 |
2 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
288 KB |
Output is correct |
6 |
Execution timed out |
5093 ms |
7252 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |