Submission #698836

# Submission time Handle Problem Language Result Execution time Memory
698836 2023-02-14T11:44:30 Z finn__ Rice Hub (IOI11_ricehub) C
100 / 100
18 ms 1724 KB
#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
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 288 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 296 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 284 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 292 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 296 KB Output is correct
28 Correct 0 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 292 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 300 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 312 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 308 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 440 KB Output is correct
3 Correct 11 ms 1652 KB Output is correct
4 Correct 10 ms 1724 KB Output is correct
5 Correct 5 ms 724 KB Output is correct
6 Correct 5 ms 944 KB Output is correct
7 Correct 11 ms 1364 KB Output is correct
8 Correct 9 ms 1360 KB Output is correct
9 Correct 5 ms 704 KB Output is correct
10 Correct 5 ms 652 KB Output is correct
11 Correct 12 ms 1684 KB Output is correct
12 Correct 18 ms 1684 KB Output is correct
13 Correct 9 ms 860 KB Output is correct
14 Correct 8 ms 852 KB Output is correct
15 Correct 11 ms 1308 KB Output is correct
16 Correct 9 ms 1288 KB Output is correct
17 Correct 12 ms 1548 KB Output is correct
18 Correct 10 ms 1592 KB Output is correct
19 Correct 10 ms 1660 KB Output is correct
20 Correct 13 ms 1652 KB Output is correct