Submission #234968

# Submission time Handle Problem Language Result Execution time Memory
234968 2020-05-26T13:09:01 Z Nodir_Bobiev Rice Hub (IOI11_ricehub) C++17
17 / 100
19 ms 896 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;

int besthub(int R, int L, int X[], long long B)
{
	int ans = 1;
	long long sumL[R+2]={}, sumR[R+2]={};
	for( int i = 1; i <= R; i ++ ){
		sumL[i] = sumL[i-1] + X[i-1];
	}
	for( int i = R; i >= 1; i -- ){
		sumR[i] = sumR[i+1] + X[i-1];
	}
	for( int i = 1; i <= R; i ++ ){
		int l = i, r = R+1;
		while(r-l>1){
			int m = (l+r)>>1;
			long long mid = (sumL[m]-sumL[i-1])/(m-l+1);
			int ll = i, rr = m+1;
			while( rr-ll>1 ){
				int mm=(ll+rr)>>1;
				if(X[mm-1]>mid)
					rr = mm;
				else
					ll = mm;
			}
			bool t = false;
			if( mid*1ll*(ll-i+1)-(sumL[ll]-sumL[i-1])+
				(sumR[ll]-sumR[m+1])-mid*1ll*(m-ll+1) <= B )
				t = true;
			if( mid < X[r-1] && (mid+1)*1ll*(ll-i+1)-(sumL[ll]-sumL[i-1])+
				(sumR[ll+1]-sumR[m+1])-(mid+1)*1ll*(m-ll) <= B )
				t = true;
			
			if( t ){
				ans = max(ans, m-i+1);
				l = m;
			}
			else r = m;
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Incorrect 5 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 896 KB Output is correct
2 Incorrect 19 ms 896 KB Output isn't correct
3 Halted 0 ms 0 KB -