Submission #384334

#TimeUsernameProblemLanguageResultExecution timeMemory
384334cpp219Rice Hub (IOI11_ricehub)C++14
100 / 100
17 ms2540 KiB
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 1e5 + 9;
const ll inf = 1e9 + 7;
ll b[N];

ll Get(ll L,ll R){
    return b[R] - b[L - 1];
}

bool chk(int m,int n,ll B){
    for (ll i = 0;i < n - m + 1;i++){
        ll L = i,R = i + m - 1;
        ll mid = (L + R)/2; ll val = b[mid] - b[mid - 1];
        ll kq = val*(mid - L + 1) - Get(L,mid) + Get(mid,R) - val*(R - mid + 1);
        if (kq <= B) return 1;
    }
    //exit(0);
    return 0;
}

int besthub(int n,int lim,int a[],ll B){
    ll l,m,h; b[0] = a[0];
    for (ll i = 1;i < n;i++) b[i] = b[i - 1] + a[i]; //cout<<b[4]<<" "<<a[5]; exit(0);
    l = 0; h = n; //cout<<chk(4,n,B); exit(0);
    while(l <= h){
        m = (l + h)/2;
        if (chk(m,n,B)) l = m + 1;
        else h = m - 1;
    }
    return h;
}
/*
ll n,a[N],lim,B;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        //freopen(task".out","w",stdout);
    }
    cin>>n>>lim>>B;
    for (ll i = 1;i <= n;i++) cin>>a[i];
    cout<<besthub(n,lim,a,B);
}
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...