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