Submission #109151

# Submission time Handle Problem Language Result Execution time Memory
109151 2019-05-04T23:19:21 Z pamaj Rice Hub (IOI11_ricehub) C++14
100 / 100
30 ms 3376 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
#define int long long

int pref[maxn], v[maxn];

int find_min_cost(int i, int j)
{
	int ct = 0;
	int media = (int)(j + i)/2;

	ct = v[media]*(2*media - i - j) + pref[j] - pref[media];

	if(i != 0) ct += pref[i - 1];

	if(media != 0) ct -= pref[media - 1];

	return ct;
}

int32_t besthub(int32_t R, int32_t L, int32_t X[], long long B)
{
	for(int i = 0; i < R; i++)
	{
		if(i) pref[i] = pref[i - 1] + X[i];
		else pref[i] = X[i]; 
		v[i] = X[i];
	}

	int best = 0;

	int l = 0, r = 0;

	while(l <= r)
	{
		best = max(best, r - l + 1);

		if(r + 1 < R)
		{
			if(find_min_cost(l, r + 1) <= B) r++;

			if(find_min_cost(l, r + 1) > B)
			{
				r++;

				while(find_min_cost(++l, r) > B);
			}
		}
		else break;
	} 
	
	return best;
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 368 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 896 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 17 ms 3328 KB Output is correct
4 Correct 17 ms 3376 KB Output is correct
5 Correct 8 ms 1664 KB Output is correct
6 Correct 8 ms 1664 KB Output is correct
7 Correct 16 ms 3200 KB Output is correct
8 Correct 21 ms 3192 KB Output is correct
9 Correct 9 ms 1664 KB Output is correct
10 Correct 14 ms 1656 KB Output is correct
11 Correct 22 ms 3328 KB Output is correct
12 Correct 30 ms 3320 KB Output is correct
13 Correct 11 ms 1664 KB Output is correct
14 Correct 11 ms 1792 KB Output is correct
15 Correct 17 ms 2560 KB Output is correct
16 Correct 18 ms 2560 KB Output is correct
17 Correct 24 ms 3064 KB Output is correct
18 Correct 25 ms 3072 KB Output is correct
19 Correct 21 ms 3200 KB Output is correct
20 Correct 20 ms 3192 KB Output is correct