#include<bits/stdc++.h>
using namespace std;
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v)
{
int n=c.size();
int q=l.size();
if(n<=2000 && q<=2000)
{
vector<int>ans(n,0);
for(int i=0;i<q;i++)
{
for(int j=l[i];j<=r[i];j++)
{
if(v[i]>0)ans[j]=min(c[j],ans[j]+v[i]);
else ans[j]=max(0,ans[j]+v[i]);
}
}
return ans;
}
vector<long long>add(n+1,0);
vector<long long>ans(n,0);
for(int i=0;i<q;i++)
{
add[l[i]]+=v[i];
add[r[i]+1]-=v[i];
}
for(int i=0;i<n;i++)
{
if(i!=0)ans[i]=ans[i-1];
ans[i]+=add[i];
}
for(int i=0;i<n;i++)
{
if(ans[i]>c[i])ans[i]=c[i];
}
vector<int>ca;
for(long long i:ans)ca.push_back(i);
return ca;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
10836 KB |
Output is correct |
2 |
Correct |
96 ms |
10836 KB |
Output is correct |
3 |
Correct |
94 ms |
10840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
52 ms |
4956 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 |
4948 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 |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
100 ms |
10836 KB |
Output is correct |
7 |
Correct |
96 ms |
10836 KB |
Output is correct |
8 |
Correct |
94 ms |
10840 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Incorrect |
52 ms |
4956 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |