Submission #234993

#TimeUsernameProblemLanguageResultExecution timeMemory
234993Nodir_BobievRice Hub (IOI11_ricehub)C++17
100 / 100
34 ms2304 KiB
    #include "ricehub.h"
    #include <bits/stdc++.h>
    using namespace std;
     
    int besthub(int R, int L, int X[], long long B)
    {
    	int ans = 0;
    	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];
    	}
    	int l = 1, r = 1;
    	while( r <= R ){
    		//cout << l << ' '<< r << endl;
    		long long ll = (l+r)>>1;
    		bool t = false;
    		if( X[ll-1]*(ll-l+1)-(sumL[ll]-sumL[l-1])+
    			(sumR[ll]-sumR[r+1])-X[ll-1]*(r-ll+1) <= B )
    			t = true;
    		if( ++ll <= r && X[ll-1]*(ll-l+1)-(sumL[ll]-sumL[l-1])+
    						(sumR[ll]-sumR[r+1])-X[ll-1]*(r-ll+1) <= B )
    			t = true;
    		if( t ){
    			ans = max(ans, r-l+1);
    			r++;
    		}
    		else l ++;
    	}
    	return ans;
    }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...