#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 ALL(x) begin(x), end(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);
int lo = 0, hi = 0, dif = 0;
vi32 s(n);
// vi32 realS(n);
loop(q, j)
{
if (v[j] > 0)
{
int d = v[j] + dif;
if (d >= 0)
{
hi += d; // wat als d < 0?
dif = 0;
lo -= v[j];
lo = max(lo, 0LL);
}
else
{
dif += v[j];
}
}
else
{
lo -= v[j];
if (lo < 0)
dif -= lo;
dif += v[j];
if (-dif >= lo)
{
lo = -dif;
}
if (lo >= hi)
{
lo = hi = dif = 0;
}
}
// assert(s == realS);
}
loop(n, i)
{
// realS[i] += v[j];
if (lo <= c[i] && c[i] <= hi)
{
s[i] = c[i] + dif;
}
else if (c[i] > hi)
s[i] = hi + dif;
else
s[i] = lo + dif;
if (s[i] < 0)
s[i] = 0;
if (s[i] > c[i])
s[i] = c[i];
// if (realS[i] < 0) realS[i] = 0; if (realS[i] > c[i]) realS[i] = c[i];
}
return s;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
70 ms |
9848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |