#include "candies.h"
#include "bits/stdc++.h"
using namespace std;
const int N = 2e5+5;
vector<int> add[N], rem[N];
int arr[N];
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> s(n);
for (int i = 0; i < q; i++){
add[l[i]].push_back(i);
rem[r[i]].push_back(i);
}
for (int i = 0; i < n; i++){
for (auto pos: add[i])
arr[pos] = v[pos];
int sum = 0, mn = 0, mx = 0, pos = -1;
for (int j = q-1; j >= 0; j--){
sum += arr[j];
mx = max(mx, sum);
mn = min(mn, sum);
if (mx - mn > c[i]){
pos = j;
break;
}
}
if (~pos){
sum -= arr[pos];
if (arr[pos] > 0)
s[i] = sum + c[i];
else
s[i] = sum;
}
else
s[i] = sum;
for (auto pos: rem[i])
arr[pos] = 0;
}
return s;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1294 ms |
24712 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
9620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |