Submission #91243

# Submission time Handle Problem Language Result Execution time Memory
91243 2018-12-26T15:53:28 Z arman_ferdous Rice Hub (IOI11_ricehub) C++17
83 / 100
35 ms 2560 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 1e5+10;

int n; ll arr[N], sum[N];

ll get(ll l, ll r, ll M) {
	ll ret = 0;
	if(arr[r] <= M) return (r - l + 1) * M - sum[r] + sum[l-1];
	if(M <= arr[l]) return sum[r] - sum[l-1] - (r - l + 1) * M;
	int p = lower_bound(arr,arr+n,M) - arr;
	return M * (p - l) - sum[p-1] + sum[l-1] + sum[r] - sum[p-1] - M * (r - p + 1);
}

int besthub(int R, int L, int X[], ll B) {
	n = R;
	for(int i = 1; i <= n; i++) arr[i] = X[i-1];
	for(int i = 1; i <= n; i++) sum[i] = sum[i-1] + arr[i];

	int lo = 1, hi = n, ans = 1;
	while(lo <= hi) {
		int mid = (lo + hi) >> 1;
		int can = 0;
		for(int i = 1; i + mid - 1 <= n; i++) {
			int med;
			if(mid & 1) med = arr[i + mid/2];
			else med = (arr[i + mid/2] + arr[i + mid/2 + 1]) / 2;
			if(get(i, i + mid - 1, med) <= B) { can = 1; break; }
		} 
		if(can) ans = mid, lo = mid + 1;
		else hi = mid - 1;
	} return ans;
}

Compilation message

ricehub.cpp: In function 'll get(ll, ll, ll)':
ricehub.cpp:11:5: warning: unused variable 'ret' [-Wunused-variable]
  ll ret = 0;
     ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 392 KB Output is correct
2 Correct 2 ms 392 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 408 KB Output is correct
5 Correct 2 ms 408 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 672 KB Output is correct
8 Correct 2 ms 672 KB Output is correct
9 Correct 2 ms 672 KB Output is correct
10 Correct 2 ms 672 KB Output is correct
11 Correct 2 ms 672 KB Output is correct
12 Correct 2 ms 672 KB Output is correct
13 Correct 2 ms 672 KB Output is correct
14 Correct 2 ms 672 KB Output is correct
15 Correct 2 ms 672 KB Output is correct
16 Correct 2 ms 748 KB Output is correct
17 Correct 2 ms 748 KB Output is correct
18 Correct 2 ms 748 KB Output is correct
19 Correct 2 ms 748 KB Output is correct
20 Correct 2 ms 748 KB Output is correct
21 Correct 2 ms 748 KB Output is correct
22 Correct 2 ms 748 KB Output is correct
23 Correct 2 ms 748 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 2 ms 748 KB Output is correct
27 Correct 2 ms 748 KB Output is correct
28 Correct 2 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
4 Correct 1 ms 748 KB Output is correct
5 Correct 2 ms 748 KB Output is correct
6 Correct 2 ms 748 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 2 ms 748 KB Output is correct
9 Correct 2 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 2 ms 748 KB Output is correct
12 Correct 2 ms 748 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
16 Correct 2 ms 748 KB Output is correct
17 Correct 2 ms 748 KB Output is correct
18 Correct 2 ms 748 KB Output is correct
19 Correct 2 ms 748 KB Output is correct
20 Correct 2 ms 748 KB Output is correct
21 Correct 3 ms 748 KB Output is correct
22 Correct 3 ms 748 KB Output is correct
23 Correct 3 ms 748 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 2 ms 748 KB Output is correct
27 Correct 3 ms 748 KB Output is correct
28 Correct 3 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1020 KB Output is correct
2 Correct 14 ms 1024 KB Output is correct
3 Correct 15 ms 2560 KB Output is correct
4 Correct 15 ms 2560 KB Output is correct
5 Correct 19 ms 2560 KB Output is correct
6 Correct 19 ms 2560 KB Output is correct
7 Correct 13 ms 2560 KB Output is correct
8 Correct 13 ms 2560 KB Output is correct
9 Correct 23 ms 2560 KB Output is correct
10 Correct 25 ms 2560 KB Output is correct
11 Correct 16 ms 2560 KB Output is correct
12 Correct 17 ms 2560 KB Output is correct
13 Correct 35 ms 2560 KB Output is correct
14 Correct 35 ms 2560 KB Output is correct
15 Correct 13 ms 2560 KB Output is correct
16 Correct 13 ms 2560 KB Output is correct
17 Correct 15 ms 2560 KB Output is correct
18 Correct 15 ms 2560 KB Output is correct
19 Correct 16 ms 2560 KB Output is correct
20 Correct 16 ms 2560 KB Output is correct