#include "candies.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;
vector<int> solve1(vector<int> &c, vector<int> &l,vector<int> &r, vector<int> &v) {
int n = c.size(),q=l.size();
vector<int>arr(n);
for(int ind=0;ind<q;ind++){
int a=l[ind],b=r[ind],k=v[ind];
for(int i=a;i<=b;i++){
arr[i]+=k;
arr[i]=min(arr[i],c[i]);
arr[i]=max(arr[i],0);
}
}
return arr;
}
vector<int> solve2(vector<int> &c, vector<int> &l,vector<int> &r, vector<int> &v) {
int n = c.size(),q=l.size();
vector<int>arr(n);
for(int ind=0;ind<q;ind++){
int a=l[ind],b=r[ind],k=v[ind];
arr[a]+=k;
if(b+1<n){
arr[b+1]-=k;
}
}
for(int i=1;i<n;i++){
arr[i]+=arr[i-1];
}
for(int i=0;i<n;i++){
arr[i]=min(arr[i],c[i]);
}
return arr;
}
vector<int> distribute_candies(vector<int> c, vector<int> l,vector<int> r, vector<int> v) {
int n = c.size(),q=l.size();
if(n>=2000&&q<=2000){
return solve1(c,l,r,v);
}
return solve2(c,l,r,v);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
97 ms |
7268 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
224 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |