This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |