#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
int get_max_r(int ind, vector<int>& ops, int tar, bool pref) {
int ret = ind - 1;
long long min_val = 0;
for (int i = ind; i < (int) ops.size(); ++i) {
if (min_val + ops[i] < tar && ops[i] < 0) {
ret = i;
}
if (!pref) {
min_val = min(min_val + ops[i], 0LL);
} else {
min_val += ops[i];
}
}
return ret;
}
int get_max_pos(int ind, vector<int>& ops, int tar) {
int ret = ind - 1;
long long max_val = 0;
for (int i = ind; i < (int) ops.size(); ++i) {
if (max_val + ops[i] > tar && ops[i] > 0) {
ret = i;
}
max_val = max_val + ops[i];
}
return ret;
}
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
int n = c.size();
int q = l.size();
vector<vector<int>> ql(n), qr(n);
for (int i = 0; i < q; ++i) {
ql[l[i]].push_back(i);
qr[r[i]].push_back(i);
}
vector<int> s(n);
vector<int> ops(q);
for (int i = 0; i < n; ++i) {
for (int j : ql[i]) {
ops[j] = v[j];
}
int start_from = 0;
start_from = get_max_r(start_from, ops, -c[i], false) + 1;//maximumR s.t: some suf containing R is < -ci
start_from = get_max_r(start_from, ops, 0, true) + 1;//maximumR s.t: some pref is negative ( < 0)
//cout << "maximumR s.t: some suf containing R is < -ci: " << start_from << '\n';
//cout << "OPS: "; for (int j : ops) cout << j << ' ';cout << '\n';
int tmp = get_max_pos(start_from, ops, c[i]) + 1;
//cout << "TMP: " << tmp << '\n';
int sum = 0;
if (tmp != start_from) {
start_from = tmp;
sum = c[i];
}
for (int j = start_from; j < (int) ops.size(); ++j) {
sum += ops[j];
}
s[i] = sum;
for (int j : qr[i]) {
ops[j] = 0;
}
}
return s;
}
# |
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 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5032 ms |
29484 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
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 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |