对于每个i,以它为左端点的最优右端点一定是单增的,所以用单调栈维护

具体的,单调栈里放的是和单调的长为d的子段,然后枚举右端点,如果这段的和-当前长为d子段最大的和大于p的话,左端点右移同时注意单调栈里的子段的左端点不能小于当前左端点,需要一起右移

#include<iostream>
#include<cstdio>
using namespace std;
const int N=2000005;
int n,d,q[N],l=1,r,ans=d,w;
long long p,a[N],s[N],mx;
long long read()
{
long long r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
int main()
{
n=read(),p=read(),d=read();
for(int i=1;i<=n;i++)
a[i]=read(),s[i]=s[i-1]+a[i];
for(int i=d;i<=n;i++)
{
while(l<=r&&s[i]-s[i-d]>s[q[r]]-s[q[r]-d])
r--;
q[++r]=i;
while(s[i]-s[w]-s[q[l]]+s[q[l]-d]>p)
{
w++;
if(q[l]-d<w)
l++;
}
ans=max(ans,i-w);
}
printf("%d\n",ans);
return 0;
}

最新文章

  1. Spinner
  2. cookie的使用
  3. Fedora 20下配置samba服务器
  4. javascript——touch事件
  5. eclipse优化配置
  6. jQuery validate入门
  7. form不提交问题
  8. 公司用中会用到的iOS开源库和第三方组件(不断更新...)
  9. CF#418 Div2 D. An overnight dance in discotheque
  10. React 系列文章(1): npm 手动搭建React 运行实例 (新手必看)
  11. win10的MySQL客户端连接centos7虚拟机的mysql服务端连接不上解决办法
  12. js 模拟超级大LE透中头奖 统计中头奖需要购买的彩票次数以及购买总金额
  13. Python模块安装与读取Excel
  14. word交叉引用公式编号时和连公式一起引用
  15. 【二分图带权匹配】Anagram @山东省第九届省赛 A
  16. iOS项目之“返回”手势操作相关
  17. .Net Core之Swagger
  18. Android Viewpager加Fragment做界面切换时数据消失的解决方式
  19. [LintCode] Invert Binary Tree 翻转二叉树
  20. 【TCP/IP详解 卷一:协议】第二十四章 TCP的未来与性能

热门文章

  1. java序列化,看这篇就够了
  2. Spring中实现自定义事件
  3. 页面跳转到顶部---bug修改
  4. 在SUSE12中使用 Machinery 进行高级系统管理
  5. Capture and report JavaScript errors with window.onerror
  6. org.hibernate.AnnotationException: No identifier specified for entity:
  7. Unable to connect to database server to retrieve database list; Arcgis 连接不上postsql库;
  8. zookeeper的集群部署
  9. 【计算机视觉】SIFT中LoG和DoG比較
  10. 【spring+websocket的使用】