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 "ricehub.h"
#define max(x, y) ((x) > (y) ? (x) : (y))
int besthub(int R, int L, int X[], long long B)
{
int *mid = X, *begin = X, *end = X + 1, left = 1, right = 0, max_rice = 0;
long long cost = 0;
while (mid < X + R)
{
// If the cost on the right are too high to restore balance, move the
// left pointer first.
if (end < X + R && cost + *end - *mid > B)
cost -= *mid - *begin, left--, begin++;
while (end < X + R && right <= left && cost + *end - *mid <= B)
cost += *end - *mid, right++, end++;
max_rice = max(max_rice, left + right);
if (mid < X + R)
cost += (left - right) * (*(mid + 1) - *mid);
mid++, left++, right--;
}
return max_rice;
}
# | 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... |