传送门:最大子序和
思路:计算前缀和,单调队列存储下标,枚举求最小值 d[k]=d[k]-d[k-j] (1<=j<=m)
在前k个元素中长度<=m的序列的最大值,所以队列头应该是k-m~k中的最小前缀和。
代码:
- #include
- #include
- #include
- #include
- #include
- #include
- using namespace std;
- const int N=3e5+10;
- int n,m,ans,u;
- int d[N],q[N];
-
- int main()
- {
- cin>>n>>m;
-
- for(int i=1;i<=n;i++)
- {
- scanf("%d",&d[i]);
- d[i]+=d[i-1];
- }
-
- int hh=0,tt=0,res=0;
- for(int i=1;i<=n;i++)
- {
- if(q[hh]
- res=max(res,d[i]-d[q[hh]]);
- while(hh<=tt&&d[q[tt]]>=d[i]) tt--;
- q[++tt]=i;
- }
- cout<
-
- return 0;
- }
-
相关阅读:
Apache paimon 优化
肖sir__设计测试用例方法之因果图07_(黑盒测试)
网络变压器怎么判断好坏?网络滤波变压器坏了一般是什么症状?
小学生python编程---忍者大战
Spring 源码(2)Spring IOC 容器 前戏准备工作
河南分销小程序开发|三级分销玩法介绍
Python编程基础 | Python编程基础面向对象编程
七夕到了 —— 属于 Java 的浪漫,拿去吧~ 祝表白成功
Mybatis-Plus的使用
antd-vue + vue3 实现a-table动态增减行,通过a-from实现a-table行内输入验证
-
原文地址:https://blog.csdn.net/m0_62327332/article/details/126200254