This morning, Roman woke up and opened the browser with nn opened tabs numbered from 11 to nn. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.

He decided to accomplish this by closing every kk-th (2≤k≤n−12≤k≤n−1) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be bb) and then close all tabs with numbers c=b+i⋅kc=b+i⋅k that satisfy the following condition: 1≤c≤n1≤c≤n and ii is an integer (it may be positive, negative or zero).

For example, if k=3k=3, n=14n=14 and Roman chooses b=8b=8, then he will close tabs with numbers 22, 55, 88, 1111 and 1414.

After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it ee) and the amount of remaining social network tabs (ss). Help Roman to calculate the maximal absolute value of the difference of those values |e−s||e−s| so that it would be easy to decide what to do next.

Input

The first line contains two integers nn and kk (2≤k<n≤1002≤k<n≤100) — the amount of tabs opened currently and the distance between the tabs closed.

The second line consists of nn integers, each of them equal either to 11 or to −1−1. The ii-th integer denotes the type of the ii-th tab: if it is equal to 11, this tab contains information for the test, and if it is equal to −1−1, it's a social network tab.

Output

Output a single integer — the maximum absolute difference between the amounts of remaining tabs of different types |e−s||e−s|.

Examples

input

Copy

4 2
1 1 -1 1

output

Copy

2

input

Copy

14 3
-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1

output

Copy

9

Note

In the first example we can choose b=1b=1 or b=3b=3. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, e=2e=2 and s=0s=0 and |e−s|=2|e−s|=2.

In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them.

思路:按照题目去模拟即可,关闭可以认为是忽略的

代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring> using namespace std;
int a[105];
int b[105];
int c[105];
int main()
{
int n,k;
cin>>n>>k;
for(int t=1;t<=n;t++)
{
scanf("%d",&a[t]);
}
int sum1;
int sum2;
int maxn=0;
for(int t=1;t<=n;t++)
{
sum1=0;
sum2=0;
for(int j=1;j<=n;j++)
{
if((j-t)%k==0)
{
continue;
}
else if(a[j]==-1)
{
sum1++;
}
else
{
sum2++;
}
}
maxn=max(maxn,abs(sum1-sum2));
}
cout<<maxn<<endl; return 0;
}

Codeforces Round #532 (Div. 2)- A(思维)的更多相关文章

  1. Codeforces Round #532 (Div. 2)

    Codeforces Round #532 (Div. 2) A - Roman and Browser #include<bits/stdc++.h> #include<iostr ...

  2. Codeforces Round #532 (Div. 2) 题解

    Codeforces Round #532 (Div. 2) 题目总链接:https://codeforces.com/contest/1100 A. Roman and Browser 题意: 给出 ...

  3. Codeforces Round #532 (Div. 2)- B(思维)

    Arkady coordinates rounds on some not really famous competitive programming platform. Each round fea ...

  4. 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】

    https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...

  5. Codeforces Round #143 (Div. 2) (ABCD 思维场)

    题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...

  6. Codeforces Round #395 (Div. 2)(A.思维,B,水)

    A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:stan ...

  7. Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)

    A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...

  8. Codeforces Round #532 (Div. 2) F 线性基(新坑) + 贪心 + 离线处理

    https://codeforces.com/contest/1100/problem/F 题意 一个有n个数组c[],q次询问,每次询问一个区间的子集最大异或和 题解 单问区间子集最大异或和,线性基 ...

  9. Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS

    题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...

随机推荐

  1. cygwin选择安装包选项搭建NDK开发环境/配置cygwin的root权限

    9.Search是可以输入你要下载的包的名称,能够快速筛选出你要下载的包.那四个单选按钮是选择下边树的样式,默认就行,不用动.View默认是Category,建议改成full显示全部包再查,省的一些包 ...

  2. 属性操作get.Attribute()

  3. MSSQL grant权限

    --创建登录名 create login test_user with password='123456a.'; --创建用户 create user test_user for login test ...

  4. iframe自适应高度(转)

    iframe自适应高度 (2013-04-23 17:29:49) 标签: iframe 高度 自适应 js 杂谈 分类: 网页制作 有时候我们的网站需要引入其他网站的东西,比如评论,这时候就需要使用 ...

  5. Action层, Service层 和 Dao层的功能区分

    Action/Service/DAO简介:  Action是管理业务(Service)调度和管理跳转的. Service是管理具体的功能的. Action只负责管理,而Service负责实施. DAO ...

  6. OpenGL超级宝典完整源码(第五版)

    链接:https://pan.baidu.com/s/1dGQkk4T 密码:wu44 Visual Studio 2017配置OpenGL https://blog.csdn.net/qiangbi ...

  7. Spring IOC容器解析及实现原理

    最近一段时间,“容器”两个字一直萦绕在我的耳边,甚至是吃饭.睡觉的时候都在我脑子里蹦来蹦去的.随着这些天一次次的交流.讨论,对于容器的理解也逐渐加深.理论上的东西终归要落实到实践,今天就借助sprin ...

  8. p2444 病毒

    传送门 分析 先用AC自动机将所有字符串存起来,之后我们从根节点跑一遍dfs 判断时我们只需要判断这个环有没有任意一个字符串的结尾就可以判断是否安全了 注意一个节点的信息需要累加上它fail指针所指位 ...

  9. ZROI2018提高day3t3

    传送门 分析 我们对于每一个可以匹配的字符都将其从栈中弹出,然后他的哈希值就是现在栈中的字符哈希一下.然后我们便可以求出对于哪些位置它们的哈希值是一样的,即它们的状态是一致的.而这些点可以求出它们的贡 ...

  10. linux删除文件、创建文件

    1.删除文件 rm huahua.txt 2.创建文件 touch huahua.txt