Submission #302468

# Submission time Handle Problem Language Result Execution time Memory
302468 2020-09-18T17:37:17 Z nhdtxdy Rice Hub (IOI11_ricehub) C++17
68 / 100
28 ms 1920 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int nax = 1e5 + 5;
int n, maxi, a[nax], pref[nax], suff[nax];
ll b;

bool chk(int x) {
	if (x > n || x < 1) return false;
	for (int i = 1; i <= n - x + 1; ++i) {
		int l = i, r = i + x - 1;
		int median = (l + r) / 2;
		// l..(median - 1)
		// (median + 1)..r
		int num_left = max(0, (median - 1 - l) + 1);
		int num_right = max(0, r - (median + 1) + 1);
		int cost_left = a[median] * num_left - (pref[median - 1] - pref[l - 1]);
		int cost_right = suff[median + 1] - suff[r + 1] - a[median] * num_right;
		if (cost_left + cost_right <= b) return true;
	}
	return false;
}

int solve() {
	for (int i = 1; i <= n; ++i) pref[i] = pref[i - 1] + a[i];
	for (int i = n; i >= 1; --i) suff[i] = suff[i + 1] + a[i];
	int l = 1, r = n;
	while (r >= l) {
		int mid = (l + r) / 2;
		bool status = chk(mid);
		if (status) {
			if (chk(mid + 1)) l = mid + 1;
			else {
				return mid;
			}
		}
		else {
			r = mid - 1;
		}
	}
	return 1;
}

int besthub(int R, int L, int X[], long long B) {
	n = R;
	maxi = L;
	for (int i = 0; i < R; ++i) a[i + 1] = X[i];
	b = B;
	return solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 416 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 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 512 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 640 KB Output is correct
2 Correct 5 ms 672 KB Output is correct
3 Correct 19 ms 1920 KB Output is correct
4 Incorrect 28 ms 1920 KB Output isn't correct
5 Halted 0 ms 0 KB -