제출 #418614

#제출 시각아이디문제언어결과실행 시간메모리
418614TLP39쌀 창고 (IOI11_ricehub)C++14
100 / 100
15 ms2508 KiB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

ll r,l,b;
ll qs[100010]={};

ll get_dist(ll st,ll ed)
{
    ll mid=(st+ed)>>1;
    ll med=qs[mid+1]-qs[mid];
    return med*((ed-st+1)&1ll)+(qs[ed+1]-qs[mid+1])-(qs[mid+1]-qs[st]);
}

ll hi,low,av;

bool test_b(ll k)
{
    for(ll i=0;i<=r-k;i++)
    {
        if(get_dist(i,i+k-1)<=b) return true;
    }
    return false;
}

int besthub(int R, int L, int X[], long long B)
{
    r=(ll)R;
    l=(ll)L;
    b=B;
    for(int i=0;i<r;i++)
    {
        qs[i+1]=qs[i]+(ll)X[i];
    }
    hi=r;
    low=1;
    while(hi>low)
    {
        av=(hi+low+1)>>1;
        if(test_b(av)) low=av;
        else hi=av-1;
    }
    return (int)hi;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...