app开发者平台在数字化时代的重要性与发展趋势解析
938
2022-08-29
AGC 008B - Contiguous Repainting
B - Contiguous Repainting Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement 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 Input The input is given from Standard Input in the following format:
N K a1 a2 … aN Output Print the maximum possible score.
Sample Input 1 Copy 5 3 -10 10 -10 10 -10 Sample Output 1 Copy 10 Paint the following squares black: the second, third and fourth squares from the left.
Sample Input 2 Copy 4 2 10 -10 -10 10 Sample Output 2 Copy 20 One possible way to obtain the maximum score is as follows:
Paint the following squares black: the first and second squares from the left. Paint the following squares black: the third and fourth squares from the left. Paint the following squares white: the second and third squares from the left. Sample Input 3 Copy 1 1 -10 Sample Output 3 Copy 0 Sample Input 4 Copy 10 5 5 -4 -5 -8 -4 7 2 -4 0 7 Sample Output 4 Copy 17 题目要求我们每次可以给一个定长(k)的区间去进行黑白覆盖染色 最后求一种方案使得所有的
黑点的权值加起来最大
那么我们首先考虑一个性质 假如我有一个长度为k的 可滑动的窗口 那么窗口两端的所有黑点我一定可以染色 那么问题就转化成 枚举每个窗口 然后求 每个窗口的左端黑点权值是多少 右端黑点的权值是多少 然后分别加上中间一段的权值和 比一下最大最小值即可
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~