#include "candies.h"
#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(), q = l.size();
vector<int> candies(n, 0);
if (n <= 2000 && q <= 2000)
{
for (int i = 0; i < q; i++)
{
int ll = l[i], rr = r[i];
while (ll <= rr)
{
candies[ll] += v[i];
if (candies[ll] > c[ll])
candies[ll] = c[ll];
if (candies[ll] < 0)
candies[ll] = 0;
ll++;
}
}
return candies;
}
else
{
vector<int> pref1(n, 0), pref2(n, 0);
for (int i = 0; i < q; i++)
{
pref1[l[i]] += v[i];
pref2[r[i]] += v[i];
}
long long ans = 0;
for(int i=0;i<n;i++)
{
ans += pref1[i];
candies[i] = min((long long)c[i], ans);
ans -= pref2[i];
}
return candies;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
8820 KB |
Output is correct |
2 |
Correct |
81 ms |
12876 KB |
Output is correct |
3 |
Correct |
77 ms |
12760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
44 ms |
4964 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 |
42 ms |
4976 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
8820 KB |
Output is correct |
7 |
Correct |
81 ms |
12876 KB |
Output is correct |
8 |
Correct |
77 ms |
12760 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Incorrect |
44 ms |
4964 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |