2600: [Ioi2011]ricehub 前缀和乱搞

读入别把B读成int类型。。。
其他的用前缀和搞一下= =

#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int n,R,l,ans,a[100005];
ll sum[100005];
ll b;
inline ll read()
{
    ll a=0,f=1; char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1; c=getchar();}
    while (c>='0'&&c<='9') {a=a*10+c-'0'; c=getchar();}
    return a*f;
}
inline bool judge(int l,int r)
{
    int mid=l+((r-l+1)>>1);
    ll tmp=0;
    tmp+=(ll)(a[mid]*(mid-l))-(ll)(sum[mid-1]-sum[l-1]);
    tmp+=(ll)(sum[r]-sum[mid])-(ll)(a[mid]*(r-mid));
    return tmp<=b;
}
int main()
{
    n=read(); l=read(); b=read();
    for (int i=1;i<=n;i++) 
        a[i]=read(),sum[i]=sum[i-1]+(ll)a[i];
    for (int L=1;L<=n;L++)
    {
        if (R<L) R=L;
        while (judge(L,R)&&R<=n) R++;
        ans=max(ans,R-L);
    }
    cout << ans;
    return 0;
}

你可能感兴趣的:(2600: [Ioi2011]ricehub 前缀和乱搞)