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. Codeforces Round #114 (Div. 2)

    Codeforces Round #114 (Div. 2) 代码 Codeforces Round #114 (Div. 2) C. Wizards and Trolleybuses 思路 每条车的 ...

  2. spark新能优化之shuffle新能调优

    shuffle调优参数 new SparkConf().set("spark.shuffle.consolidateFiles", "true") spark. ...

  3. ExtJS参考手册

    ExtJS是一个用javascript写的,主要用于创建前端用户界面,是一个与后台技术无关的前端ajax框架.因此,可以把ExtJS用在.Net.Java.Php等各种开发语言开发的应用中.ExtJs ...

  4. CSS中控制换行的四种属性

    一.white-space 可以实现HTML中PRE标签的效果,以及单元格的noWrap效果,点此查看示例. Example Source Code 语法: white-space : normal  ...

  5. Python-属性(property)

    在2.6版本中,添加了一种新的类成员函数的访问方式--property. 原型 class property([fget[, fset[, fdel[, doc]]]]) fget:获取属性 fset ...

  6. 请让页面中的一个元素(10px*10px)围绕坐标(200, 300) 做圆周运动

    <!DOCTYPE html> <html> <head> <title>Making things move</title> <me ...

  7. jQuery easyui datagrid数据绑定

    1.绑定json数据 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type&qu ...

  8. C#→关于System.Data.Linq下的Table<TEntity> 泛型类 的问题

    Table<TEntity>表示表格记录,它是一个泛型集合类,它的元素就是表格实体对象.它提供一组方法,对元素进行添加删除操作,并可以通过DataContext将这些操作保存到数据库. 表 ...

  9. LINQ及EntityFramework何时从数据库返回数据,备忘

    Generally speaking, LINQ queries are executed when the application code processes data (for instance ...

  10. linux文件锁

    http://blog.chinaunix.net/uid-25324849-id-3077304.html 在SHELL中实现文件锁,有两种简单的方式.(1)一是利用普通文件,在脚本启动时检查特定文 ...