Submission #914764

#TimeUsernameProblemLanguageResultExecution timeMemory
914764DucNguyen2007Rice Hub (IOI11_ricehub)C++14
68 / 100
1058 ms3368 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxN=1e5+5;
ll sum[maxN+1];
int a[maxN+1];
ll get(ll l,ll r)
{
    if(l==0)
    {
        return sum[r];
    }
    else return sum[r]-sum[l-1];
}
ll besthub(int n,int L,int a[],ll B)
{
    sum[0]=a[0];
    for(int i=1;i<n;i++)
    {
        sum[i]=sum[i-1]+a[i];
    }
    ll res=0;
    for(int len=1;len<=n;len++)
    {
        ll l=0,r=len-1;
        while(r<n)
        {
            ll p=(l+r)/2;
            ll cur=(p-l+1)*a[p]-get(l,p)+get(p,r)-(r-p+1)*a[p];
            if(cur<=B)
            {
                res=max(res,1LL*len);
            }
            l++;
            r++;
        }
    }
    return res;
}
 
/*5 20 6
1 2 10 12 14*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...