#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<long long>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],1ll*c[i]);
}
vector<int>s(n);
for(int i=0;i<n;i++){
s[i]=arr[i];
}
return s;
}
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);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
3 ms |
356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
8800 KB |
Output is correct |
2 |
Correct |
98 ms |
12880 KB |
Output is correct |
3 |
Correct |
112 ms |
12752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
56 ms |
4960 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
48 ms |
4956 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
3 ms |
356 KB |
Output is correct |
6 |
Correct |
110 ms |
8800 KB |
Output is correct |
7 |
Correct |
98 ms |
12880 KB |
Output is correct |
8 |
Correct |
112 ms |
12752 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Incorrect |
56 ms |
4960 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |