Bzoj4385 [poi2015]wilcze doły

省选前刷水

Posted by yjjr's blog on April 11, 2018

题目

Sample Input

9 7 2
3 4 1 9 4 1 7 1 3


Sample Output

5


分析

“有的选手水平不行，所以只能省选前来刷水题了。”

code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
inline ll read(){
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
//**********head by yjjr**********
const int maxn=2e6+6;
int n,d,a[maxn];ll s[maxn],f[maxn],que[maxn<<2],p;
int main()
{
n=read(),p=read(),d=read();
rep(i,1,n)a[i]=read(),s[i]=s[i-1]+a[i];
rep(i,0,n)f[i]=s[min(n,i+d)]-s[i];
int head=1,tail=1,now=0,ans=d;que[1]=0;
rep(i,d+1,n){
while(head<=tail&&f[que[tail]]<f[i-d])tail--;
que[++tail]=i-d;
while(now<i-d&&s[now]+f[que[head]]<s[i]-p){
now++;
if(now>que[head])head++;
}
ans=max(ans,i-now);
}
cout<<ans<<endl;
return 0;
}