Submission #838363

# Submission time Handle Problem Language Result Execution time Memory
838363 2023-08-26T17:18:24 Z MohamedAhmed04 Rice Hub (IOI11_ricehub) C++14
100 / 100
11 ms 2144 KB
#include <bits/stdc++.h>
#include "ricehub.h"

using namespace std ;

const int MAX = 1e6 + 10 ;

int n ;
int arr[MAX] ;
long long k ;

bool check(int m)
{
	int idx = m/2 ;
	long long suml = 0 , sumr = 0 ;
	for(int i = 0 ; i < m-1 ; ++i)
	{
		if(i < idx)
			suml += arr[i] ;
		else
			sumr += arr[i] ;
	}
	long long Min = 4e18 ;
	for(int i = m-1 ; i < n ; ++i)
	{
		sumr += arr[i] ;
		if(i >= m)
			suml -= arr[i-m] , sumr -= arr[idx] , suml += arr[idx] , ++idx ;
		long long sum = 1ll * arr[idx] * (m/2) - suml ;
		sum += sumr - 1ll * arr[idx] * ((m+1ll) / 2ll) ;
		Min = min(Min , sum) ;
	}
	return (Min <= k) ;
}

int besthub(int R, int L, int X[], long long B)
{
	n = R , k = B ;
	for(int i = 0 ; i < n ; ++i)
		arr[i] = X[i] ;
	int l = 1 , r = n ;
	int ans = 1 ;
	while(l <= r)
	{
		int mid = (l + r) >> 1 ;
		if(check(mid))
			ans = mid , l = mid+1 ;
		else
			r = mid-1 ;
	}
	return ans ;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 308 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 304 KB Output is correct
15 Correct 0 ms 240 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 304 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 10 ms 2064 KB Output is correct
4 Correct 10 ms 2132 KB Output is correct
5 Correct 6 ms 1048 KB Output is correct
6 Correct 6 ms 1048 KB Output is correct
7 Correct 10 ms 1876 KB Output is correct
8 Correct 9 ms 1764 KB Output is correct
9 Correct 5 ms 980 KB Output is correct
10 Correct 6 ms 980 KB Output is correct
11 Correct 11 ms 2056 KB Output is correct
12 Correct 10 ms 2144 KB Output is correct
13 Correct 8 ms 1000 KB Output is correct
14 Correct 6 ms 1084 KB Output is correct
15 Correct 11 ms 1608 KB Output is correct
16 Correct 8 ms 1620 KB Output is correct
17 Correct 9 ms 1880 KB Output is correct
18 Correct 10 ms 1876 KB Output is correct
19 Correct 10 ms 2068 KB Output is correct
20 Correct 10 ms 1976 KB Output is correct