B. Bear and Finding Criminals
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 citya. 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

链接:http://codeforces.com/contest/680/problem/B这题也是水题,直接看底下的NOTE,更容易懂。
#include<bits/stdc++.h>

using namespace std;

#define SI(N) scanf("%d",&(N))

int main()
{
int a[]={};
int n,in;
cin>>n>>in;
for (int i=;i<=n;i++)
{
SI(a[i]);
}
int ans=;
int l=in-,r=in+;
while(l>=&&r<=n)
{
if (a[l]==&&a[r]==)
{
ans+=;
}
l--,r++;
}
if (l==)
{
for (int i=r;i<=n;i++)
{
if (a[i]==)
ans++;
}
}
if (r==n+)
{
for (int i=l;i>=;i--)
{
if (a[i]==)
ans++;
}
}
if (a[in]==)
ans++;
printf("%d\n",ans);
return ;
}

Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)的更多相关文章

  1. Codeforces Round #356 (Div. 2) B. Bear and Finding Criminal 水题

    B. Bear and Finding Criminals 题目连接: http://www.codeforces.com/contest/680/problem/B Description Ther ...

  2. Codeforces Round #356 (Div. 2) C. Bear and Prime 100 水题

    C. Bear and Prime 100 题目连接: http://www.codeforces.com/contest/680/problem/C Description This is an i ...

  3. Codeforces Round #356 (Div. 2) A. Bear and Five Cards 水题

    A. Bear and Five Cards 题目连接: http://www.codeforces.com/contest/680/problem/A Description A little be ...

  4. Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)

    Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...

  5. codeforces 680B B. Bear and Finding Criminals(水题)

    题目链接: B. Bear and Finding Criminals //#include <bits/stdc++.h> #include <vector> #includ ...

  6. Codeforces Round #356 (Div. 2) C. Bear and Prime 100(转)

    C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standar ...

  7. Codeforces Round #373 (Div. 2) C. Efim and Strange Grade 水题

    C. Efim and Strange Grade 题目连接: http://codeforces.com/contest/719/problem/C Description Efim just re ...

  8. Codeforces Round #185 (Div. 2) A. Whose sentence is it? 水题

    A. Whose sentence is it? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  9. Codeforces Round #373 (Div. 2) A. Vitya in the Countryside 水题

    A. Vitya in the Countryside 题目连接: http://codeforces.com/contest/719/problem/A Description Every summ ...

随机推荐

  1. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  2. poj3687 拓扑序

    题意:有编号 1-n 的球,每个球的质量不同,质量从 1 到 n 不等,给出一系列比较,分别是两个编号的球的大小关系,求一个序列满足上述关系,并且从编号 1 开始依次选择可选的最小质量,输出每个球的质 ...

  3. 越狱Season 1-Episode 21: Go

    Season 1, Episode 21: Go -Michael: I need you to let me get us out of here. 我需要你帮我出去 -Patoshik: If y ...

  4. STM32的Cortex-M3核与ARM7有何区别?哪个性能更强?

  5. js类型判断

    console.log('---------------------'); var a="string"; console.log(a); //string var a=1; co ...

  6. C++ little errors , Big problem

    ---------------------------------------------------------------------------------------------------- ...

  7. compiler

    http://www.lingcc.com/2012/05/16/12048/ a list of compiler books — 汗牛充栋的编译器参考资料 Posted on 2012年5月16日 ...

  8. Intel指令集专有词解释

    SSE 概述 SSE(Streaming SIMD Extensions)是英特尔在AMD的3D Now!发布一年之后,在其计算机芯片Pentium III中引入的指令集,是MMX的超集.AMD后来在 ...

  9. C++重载,重写,重定义

    1.重载:重载是在一个类中,函数名一样,参数类型或参数个数不同的一系列函数需要注意的是,与返回类型无关. class Test { public: void show(); void show(int ...

  10. Cookielib

    Cookielib模块主要的对象有CookieJar.FileCookieJar.MozillaCookieJar.LWPCookieJar 它们的关系:CookieJar —-派生—->Fil ...