#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> vi;
typedef vector<signed> vi32;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef set<int> si;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pb push_back
#define loop(x, i) for (int i = 0; i < x; i++)
#define rev(x, i) for (int i = (int)x - 1; i >= 0; i--)
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define sz(x) (int)x.size()
vi32 distribute_candies(vi32 c, vi32 l, vi32 r, vi32 v)
{
int n = sz(c);
int q = sz(l);
vi32 s(n);
vi sufSum(q + 1);
vi sufMax(q + 1);
vi sufMin(q + 1);
vi diff(q + 1);
// map<int,int> lastIx;
rev(q, j)
{
assert(n - 1 == r[j]);
sufSum[j] = sufSum[j + 1] + v[j];
sufMin[j] = min(sufMin[j + 1], sufSum[j]);
sufMax[j] = max(sufMax[j + 1], sufSum[j]);
diff[j] = sufMax[j] - sufMin[j];
}
loop(n, i)
{
int ix = q - (lower_bound(RALL(diff), c[i]) - diff.rbegin());
if (ix == -1)
{
s[i] = sufSum[0];
continue;
}
if (sufSum[ix] == sufMax[ix])
{
int mn = sufMin[ix];
int mnIx = upper_bound(ALL(sufMin), mn) - sufMin.begin() - 1;
s[i] = c[i] + sufSum[mnIx];
}
else
{
int mx = sufMax[ix];
int mxIx = q - (lower_bound(RALL(sufMax), mx) - sufMax.rbegin());
s[i] = sufSum[mxIx];
}
}
return s;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
61 ms |
27380 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
34 ms |
11256 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |