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

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
#include
#include
#include

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<

 

你可能感兴趣的:(codefores水题,思维题)