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

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;
} 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

black-hole6

你的鼓励将是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值