题目描述

There are N squares aligned in a row. The i-th square from the left contains an integer ai.

Initially, all the squares are white. Snuke will perform the following operation some number of times:

Select K consecutive squares. Then, paint all of them white, or paint all of them black. Here, the colors of the squares are overwritten.
After Snuke finishes performing the operation, the score will be calculated as the sum of the integers contained in the black squares. Find the maximum possible score.

Constraints
1≤N≤105
1≤K≤N
ai is an integer.
|ai|≤109

输入

The input is given from Standard Input in the following format:

N K
a1 a2 … aN

输出

Print the maximum possible score.

样例输入

5 3
-10 10 -10 10 -10

样例输出

10

提示

Paint the following squares black: the second, third and fourth squares from the left.Contiguous Repainting

除了最后一次刷,再这一k段序列的其他正数都可以取到

把这k段序列当作刷白的中转站,反正就算黑了几个再把这k个刷白。

最后再考虑这k个要不要刷黑

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+;
ll s[maxn],a[maxn];
int main(){
int n,k,t;
cin>>n>>k;
for(int i=;i<=n;i++){
cin>>t;
s[i]=s[i-]+t;
a[i]=a[i-];
if(t>) a[i]+=t;
}
ll ans=;
for(int i=;i+k-<=n;i++){
ll sum=a[n]-(a[i+k-]-a[i-]);
if(s[i+k-]-s[i-]>) sum+=s[i+k-]-s[i-];
ans=max(ans,sum);
}
cout<<ans<<endl;
return ;
}

最新文章

  1. showPrompt弹框提示
  2. 跟着百度学PHP[4]OOP面对对象编程-4-对象成员的访问 -&gt;
  3. MVC中使用RazorPDF创建PDF
  4. UVa OJ 175 - Keywords (关键字)
  5. java 框架Nutz
  6. BZOJ 4198 荷马史诗
  7. 【转】简单内存泄漏检测方法 解决 Detected memory leaks! 问题
  8. xfire发布的Webservice中Spring注入为空的解决方案
  9. Kali Linux 装好系统后安装经常使用软件
  10. AngularJS1.X学习笔记3-内置模板指令
  11. 深入了解mysql数据传输编码原理
  12. Android Weekly Notes Issue #286
  13. .Net Core实践2 sqlite
  14. ASPxGridView 添加勾选列--全选 和 后端获取勾的行ID
  15. linux批量替换文件内容3种方法(perl,sed,shell)
  16. backgroud 应用减小资源大小和请求数
  17. HDU6152
  18. Python3之hashlib
  19. ASP.NET:插件化机制
  20. 【脚本开发】:性能测试-Java虚拟用户实现下载脚本

热门文章

  1. Android如何用一个TextView显示不同颜色得字符
  2. UML-基于GRASP对象设计步骤
  3. javaweb06 文件的下载
  4. JavaScript学习总结(八)
  5. Ubuntu的man中文包安装
  6. L0,L1,L2正则化浅析
  7. 代码杂谈-split函数
  8. nvm安装教程
  9. 吴裕雄--天生自然Linux操作系统:Linux 简介
  10. python3.x设置默认编码(sys.stdout.encoding和sys.defaultencoding)