제출 #698836

#제출 시각아이디문제언어결과실행 시간메모리
698836finn__쌀 창고 (IOI11_ricehub)C11
100 / 100
18 ms1724 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...