Submission #311352

# Submission time Handle Problem Language Result Execution time Memory
311352 2020-10-10T00:51:29 Z LucaDantas Rice Hub (IOI11_ricehub) C++17
100 / 100
26 ms 2432 KB
#include "ricehub.h"
#include<algorithm>
#include<cstdio>
#include <cassert>

using ll = long long;

constexpr int maxn = 1e5+10;

ll pref[maxn];

inline ll itv(int l, int r) { return pref[r] - (l?pref[l-1]:0); }

ll cost(int l, int r, int a[]) {
	if(l == r) return 0;
	int m = (l+r) >> 1;
	int pos = a[m];
	ll cost = 1ll*pos*(m-l+1) - itv(l, m);
	cost += itv(m+1, r) - 1ll*pos*(r-m);
	return cost;
}

int besthub(int n, int l, int a[], ll b)
{
	int ans = 0;
	pref[0] = a[0];
	for(int i = 1; i < n; i++)
		pref[i] = pref[i-1]+a[i];
	for(int i = 0; i < n; i++) {
		int l = i, r = n-1, best = -1;
		while(l <= r) {
			int m = (l+r) >> 1;
			if(cost(i, m, a) <= b)
				best = m, l = m+1;
			else
				r = m-1;
		}
		// printf("%d %d\n", i, best);
		assert(best != -1);
		ans = std::max(ans, best - i + 1);
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 304 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 0 ms 256 KB Output is correct
24 Correct 0 ms 256 KB Output is correct
25 Correct 0 ms 256 KB Output is correct
26 Correct 0 ms 256 KB Output is correct
27 Correct 0 ms 256 KB Output is correct
28 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 404 KB Output is correct
25 Correct 1 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 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 24 ms 1536 KB Output is correct
4 Correct 24 ms 1400 KB Output is correct
5 Correct 11 ms 896 KB Output is correct
6 Correct 11 ms 896 KB Output is correct
7 Correct 22 ms 1528 KB Output is correct
8 Correct 23 ms 1408 KB Output is correct
9 Correct 10 ms 896 KB Output is correct
10 Correct 10 ms 896 KB Output is correct
11 Correct 26 ms 1408 KB Output is correct
12 Correct 26 ms 1536 KB Output is correct
13 Correct 11 ms 896 KB Output is correct
14 Correct 12 ms 1280 KB Output is correct
15 Correct 20 ms 1920 KB Output is correct
16 Correct 20 ms 1920 KB Output is correct
17 Correct 24 ms 2304 KB Output is correct
18 Correct 24 ms 2304 KB Output is correct
19 Correct 25 ms 2432 KB Output is correct
20 Correct 25 ms 2432 KB Output is correct