Submission #308258

# Submission time Handle Problem Language Result Execution time Memory
308258 2020-09-30T15:40:07 Z amunduzbaev Rice Hub (IOI11_ricehub) C++14
100 / 100
21 ms 2048 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int a[N], n;
long long b;
bool check(int cnt){
	//two pointers?
	if(cnt == 1){
		return true;
	}
	int l=0, r=cnt-1;
	long long suml = 0, sumr = 0;
	long long m = a[(cnt-1)/2];
	for(int i=0; i<cnt/2; i++)suml += m-a[i];
	for(int i=cnt/2;i<cnt;i++)sumr += a[i]-m;
	
	bool flag = false;
	while(true){
	//	cout << suml << ' ' << sumr << '\n';
		if(b >= suml + sumr)flag = true;
		
		l++, r++;
		int median = l + (cnt-1)/2;
		if(r >= n)break;
		suml -= a[median-1]-a[l-1];
		suml += ((cnt-1)/2)*(a[median]-a[median-1]);
		sumr -= ((cnt)/2)*(a[median]-a[median-1]);
		sumr += a[r]-a[median];
	}
	return flag;
}
int besthub(int R, int L, int X[], long long B){
	n = R;
	b = B;
	for(int i=0;i<n;i++)a[i] = X[i];
	int l=0, r=R+1;
//	cout << check(2) << '\n';
	while(l+1<r){
		int mid = (l+r)/2;
		if(check(mid)){
			l = mid;
		}else {
			r = mid;
		}
	}
	return l;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 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 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 0 ms 384 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 384 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 1 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 288 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 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 384 KB Output is correct
13 Correct 1 ms 384 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 1 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 2 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 640 KB Output is correct
2 Correct 4 ms 640 KB Output is correct
3 Correct 20 ms 1920 KB Output is correct
4 Correct 19 ms 1920 KB Output is correct
5 Correct 10 ms 1024 KB Output is correct
6 Correct 10 ms 1024 KB Output is correct
7 Correct 17 ms 1920 KB Output is correct
8 Correct 17 ms 2048 KB Output is correct
9 Correct 9 ms 1024 KB Output is correct
10 Correct 9 ms 1024 KB Output is correct
11 Correct 21 ms 1912 KB Output is correct
12 Correct 21 ms 1920 KB Output is correct
13 Correct 10 ms 1152 KB Output is correct
14 Correct 11 ms 1188 KB Output is correct
15 Correct 16 ms 1664 KB Output is correct
16 Correct 16 ms 1664 KB Output is correct
17 Correct 18 ms 1792 KB Output is correct
18 Correct 19 ms 1792 KB Output is correct
19 Correct 20 ms 1920 KB Output is correct
20 Correct 20 ms 1920 KB Output is correct