Submission #1217231

#TimeUsernameProblemLanguageResultExecution timeMemory
1217231lizi14Rice Hub (IOI11_ricehub)C++20
In queue
0 ms0 KiB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;

int besthub(int R, int L, int X[], long long B)
{
    
    int l=0,r=R;
    long long bati=0;
    while(l<=r){
        int mid=(l+r)/2;
        //long long ans=0;
        int ka=0;
        for(int i=0; i+mid<=R; i++){
            long long ans=0;
            for(int j=i; j<i+mid; j++){
                ans+=abs(X[i+(mid+1)/2-1]-X[j]);
            }
            //ans=min(ans,ans1);
            if(ans<=B){
                ka=1;
                //l=mid+1;
                break;
            }
            
        }
        if(ka==1){
            l=mid+1;
        }
        else{
            r=mid-1;
        }
    }
    
    return r;
}