Submission #1316377

#TimeUsernameProblemLanguageResultExecution timeMemory
1316377warrennRice Hub (IOI11_ricehub)C++20
100 / 100
7 ms1336 KiB
#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long 

int besthub(int R, int L, int x[], ll B){
  ll l=1,r=R;
  int ans=0;

  ll pref[R+1];
  pref[0]=0;
  for(int q=1;q<=R;q++){
    pref[q]=pref[q-1]+x[q-1];
  }


  while(l<=r){
    ll mid=(l+r)/2;

    bool yey=false;
    for(ll q=mid;q<=R;q++){
      ll posl=q-mid+1,tng=(posl+q)/2;

      ll cost=(x[tng-1]*(tng-posl+1));
      cost-=(pref[tng]-pref[posl-1]);

      cost+=(pref[q]-pref[tng]);
      cost-=x[tng-1]*(q-tng);

      if(cost<=B){
      //  cout<<cost<<" "<<mid<<endl;
        yey=true;break;
      }
    }

    if(yey){
      ans=mid;
      l=mid+1;
    }
    else{
      r=mid-1;
    }

  }
  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...