제출 #797774

#제출 시각아이디문제언어결과실행 시간메모리
797774farhan132쌀 창고 (IOI11_ricehub)C++17
100 / 100
12 ms2904 KiB
#include "ricehub.h"

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef double dd;
typedef pair<ll , ll> ii;
typedef tuple < ll,  ll, ll > tp;
 
#define ff first
#define ss second
#define pb push_back
#define in insert

int besthub(int R, int L, int x[], long long B){

  vector < ll > pref(1, x[0]);
  for(ll i = 1; i < R; i++){
    pref.pb(pref.back() + x[i]);
  }

  ll l = 1, r = R;
  ll ans = 0;

  while(l <= r){
    ll m = (l + r) / 2;
    bool f = 0;
    for(ll i = 0; i + m - 1 < R; i++){
      ll k = (i + i + m - 1) / 2;
      ll cost = (pref[i + m - 1] - x[k] * (i + m - 1 - k)) + (x[k] * (k - i + 1) - pref[k]);
      cost -= pref[k];
      if(i){
        cost += pref[i - 1];
      }
      if(cost <= B){
        ans = m; f = 1;
      }
    }
    if(f){
      l = m + 1;
    }else{
      r = m - 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...