제출 #696766

#제출 시각아이디문제언어결과실행 시간메모리
696766vjudge1쌀 창고 (IOI11_ricehub)C++17
100 / 100
18 ms2516 KiB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
long long pf[maxn], ki, ka, mid, idxtengah, cost, res, ans;

int besthub(int R, int L, int X[], long long B)
{
  for(int i=0; i<R; i++) {
    pf[i]=X[i]+(i?pf[i-1]:0);
    ki=0, ka=i;
    while(ki<=ka) {
      mid=(ki+ka)/2, idxtengah=(mid+i)/2;
      cost=(idxtengah-mid)*X[idxtengah]-((idxtengah?pf[idxtengah-1]:0)-(mid?pf[mid-1]:0));
      cost+=pf[i]-pf[idxtengah]-((i-idxtengah)*X[idxtengah]);
      if(cost<=B) res=mid, ka=mid-1;
      else ki=mid+1;
    }
    ans=max(ans, i-res+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...