#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 (mx - mn > c[i]){
if (arr[pos] > 0)
s[i] = c[i] + mn;
else
s[i] = mx;
}
else
s[i] = mx;
for (auto pos: rem[i])
arr[pos] = 0;
}
return s;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9684 KB |
Output is correct |
3 |
Correct |
4 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9684 KB |
Output is correct |
5 |
Correct |
6 ms |
9812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1252 ms |
24716 KB |
Output is correct |
2 |
Execution timed out |
5049 ms |
24616 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
506 ms |
18040 KB |
Output is correct |
3 |
Correct |
499 ms |
13360 KB |
Output is correct |
4 |
Execution timed out |
5049 ms |
24652 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9684 KB |
Output is correct |
3 |
Correct |
131 ms |
16964 KB |
Output is correct |
4 |
Correct |
169 ms |
12232 KB |
Output is correct |
5 |
Execution timed out |
5073 ms |
19220 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9684 KB |
Output is correct |
3 |
Correct |
4 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9684 KB |
Output is correct |
5 |
Correct |
6 ms |
9812 KB |
Output is correct |
6 |
Correct |
1252 ms |
24716 KB |
Output is correct |
7 |
Execution timed out |
5049 ms |
24616 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |