CodeForces 680A 680B

680A:Bear and Five Cards

简单判断 计算

#include
#include
#include
#include
using namespace std;
int main()
{
	int a[5],sum,i,flag,j1,j2;
	while(scanf("%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4])!=EOF)
	{
		sum=0;flag=0;j1=0;j2=0;
		sort(a,a+5);
		for(i=0;i<5;i++)
		{
			sum+=a[i];
		  if(a[i]==a[i+1]&&a[i+1]!=a[i+2])
		  {
		  	if(a[i]>flag)   flag=a[i];j1=2*a[i];
		  }
		  if(a[i]==a[i+1]&&a[i]==a[i+2])
		  {
		  	j2=3*a[i];
		  }
		} 
		if(j1>j2)  sum-=j1;
		else sum-=j2;
		printf("%d\n",sum);
	}
	return 0;
}

 680B:Bearing and Finding Criminals

There are n cities in Bearland, numbered 1 through n. Cities are arranged in one long row. The distance between cities i and j is equal to |i - j|.

Limak is a police officer. He lives in a city a. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he knows that there is at most one criminal in each city.

Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city a. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal.

You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD.

Input

The first line of the input contains two integers n and a (1 ≤ a ≤ n ≤ 100) — the number of cities and the index of city where Limak lives.

The second line contains n integers t1, t2, ..., tn (0 ≤ ti ≤ 1). There are ti criminals in the i-th city.

Output

Print the number of criminals Limak will catch.

Examples

Input

6 3
1 1 1 0 1 0

Output

3

Input

5 2
0 0 0 1 0

Output

1

 捉贼:要确定警察是在前半段还是后半段,以他为对称轴计算到一边到顶,后计算剩余的地方。

#include
#include
#include
#include
using namespace std;
int main()
{
	int n,a,i,t[105],begin=0,b=0,end=0,count=0;
	scanf("%d%d",&n,&a);
	for(i=0;in) {
	begin=2*a-n-1;b=0;end=begin;}
    else {
	begin=0;b=2*a-1;end=n;}
	for(i=begin;i

 

你可能感兴趣的:(题目)