Contiguous Repainting
题目描述
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
输入
N K
a1 a2 … aN
输出
样例输入
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 ;
}
Contiguous Repainting的更多相关文章
- AtCoder Grand Contest 008
AtCoder Grand Contest 008 A - Simple Calculator 翻译 有一个计算器,上面有一个显示按钮和两个其他的按钮.初始时,计算器上显示的数字是\(x\),现在想把 ...
- A@[G!C]%008
A@[G!C]%008 A Simple Calculator 细节题. B Contiguous Repainting 最后只要有连续\(K\)个鸽子同色就可以构造方案,枚举+前缀和 C Tetro ...
- 【AtCoder】AGC008
AGC008 A - Simple Calculator 如果符号相同,那么如果y比x大直接走,否则需要两次反号 如果符号不同,需要绝对值的差加一次反号 如果有一个是0,且y比x要小,那只需要一次反号 ...
- [CareerCup] 17.8 Contiguous Sequence with Largest Sum 连续子序列之和最大
17.8 You are given an array of integers (both positive and negative). Find the contiguous sequence w ...
- 论文阅读之 DECOLOR: Moving Object Detection by Detecting Contiguous Outliers in the Low-Rank Representation
DECOLOR: Moving Object Detection by Detecting Contiguous Outliers in the Low-Rank Representation Xia ...
- Find longest contiguous sub array
It's still an Amazon interview question. Given an array containing only stars '*' and hashes '#' . F ...
- [LeetCode] Contiguous Array 邻近数组
Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1. ...
- [Swift]LeetCode525. 连续数组 | Contiguous Array
Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1. ...
- 994.Contiguous Array 邻近数组
描述 Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and ...
随机推荐
- PHP 的变量类型,变量检测
1.PHP的变量类型: 整型 浮点型 字符串 布尔型 数组 对象 null 资源类型 一个变量就是一个盒子,类型可以看做盒子的标签,变量的值就是盒子里的内容 null 是没有类型的空盒子, ...
- Bugku 加密(持续更新)
1.滴答~滴 不多说,摩斯密码解密. 2.聪明的小羊 栅栏密码解密. 3.ok Ook解密 4.这不是摩斯密码 brainfuck解码 5.简单加密 凯撒有两种编码脚本,一种是字母26内循环移位,一种 ...
- DevOps专题 | 大型企业级监控系统设计
10月30日,全球权威数据调研机构IDC正式发布<IDCMarketScape: 中国DevOps云市场2019,厂商评估>报告.京东云凭借丰富的场景和实践能力,以及高质量的服务交付和平台 ...
- Luogu P3031 高于中位数
定义序列\(x_i = f([H_i >=x])\;\;\;\;其中f(0) = -1,f(1) = 1\),那么区间[i,j]满足条件当且仅当sum_j-sum_{i-1} > 0,即s ...
- [Python]h5py/__init__.py:36:
个人博客地址:https://www.bearoom.xyz/2019/08/24/python-devolop-env-hdf5-problem/ 安装tensorflow之后,在导入tensorf ...
- 系统 win 10 专业版 下载地址
thunder://QUFodHRwOi8veHoyLjgxMDg0MC5jb20vY25fd2luZG93c18xMF9jb25zdW1lcl9lZGl0aW9uc192ZXJzaW9uXzE4MD ...
- goahead调试经验
一.参考网址 1.源码的github地址 2.Web开发之Goahead 二.技术细节 1.默认网页的存放目录和名称 1)目录:在main.c文件中有*rootWeb定义,如: 2)网页名:在mai ...
- Django框架(九):视图(二) HttpRequest对象、HttpResponse对象
1. HttpRequest对象 服务器接收到http协议的请求后,会根据报文创建HttpRequest对象,这个对象不需要我们创建,直接使用服务器构造好的对象就可以.视图的第一个参数必须是HttpR ...
- P3252 [JLOI2012]树
题目描述 在这个问题中,给定一个值S和一棵树.在树的每个节点有一个正整数,问有多少条路径的节点总和达到S.路径中节点的深度必须是升序的.假设节点1是根节点,根的深度是0,它的儿子节点的深度为1.路径不 ...
- 计蒜客 密码锁(BFS)
https://www.jisuanke.com/course/1797/121114 Description 现在一个紧急的任务是打开一个密码锁.密码由四位数字组成,每个数字从 1 到 9 进行编号 ...