#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> distribute_candies(vector<int> c, vector<int> lf, vector<int> rg, vector<int> v) {
int n = c.size(), q = lf.size();
vector<ll> p = {v[0]}, smax(q), smin(q);
for (int i = 1; i < q; i++){
p.push_back(p.back() + v[i]);
}
smax[q - 1] = smin[q - 1] = p[q - 1];
for (int i = q - 2; i >= 0; i--){
smax[i] = max(smax[i + 1], p[i]);
smin[i] = min(smin[i + 1], p[i]);
}
vector<int> ans(n);
for (int i = 0; i < n; i++){
int l = 0, r = q - 1;
int j = 0;
while (l < r){
int m = (l + r) >> 1;
if (smax[m] - smin[m] >= c[i]){
j = m;
l = m + 1;
} else r = m - 1;
}
// cerr << i << ' ' << j << endl;
if (p[j] == smax[j]) ans[i] = c[i] - (p[q - 1] - p[j]); else
ans[i] = p[q - 1] - p[j];
}
return ans;
}
/*
1
8
6
0 0 5
0 0 -3
0 0 -1
0 0 2
0 0 6
0 0 -4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
138 ms |
11940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |