Description

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.

Sample Input

Input
6 3
1 1 1 0 1 0
Output
3
Input
5 2
0 0 0 1 0
Output
1

题意:共有n座城市,Limak在第a座城市,每做城市的距离即序列号相减的绝对值。米格城市最多有一名罪犯,BCD可以告诉Limak在某个距离处有多少罪犯,如果Limak确定罪犯在哪个城市,就可以抓到他,求他可以抓住多少罪犯。

如:

1 1 1 0 1 0   Limak在第三位,则BCD可知距离为1处有1名罪犯,则Limak不能确定在哪个城市故无法抓到;距离为2处有两名,则确定每个城市必有一名,故抓到两名;距离为3处有一名,因为距离为3 的城市只有一座,也能确定,故抓住一名。

附AC代码:

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std; int n,m;
int a[]; int main(){
while(cin>>n>>m){
int sum=;
memset(a,,sizeof(a));
for(int i=;i<=n;i++){
cin>>a[i];
}
for(int i=;i<n;i++){
if(m-i<&&m+i<=n){
if(a[m+i]==){
sum++;
continue;
}
}
if(m+i>n&&m-i>=){
if(a[m-i]==){
sum++;
continue;
}
}
if(a[m-i]==&&a[m+i]==){
if(m-i==m+i){
sum++;
continue;
}
else{
sum+=;
continue;
} }
}
cout<<sum<<endl;
}
return ;
}

D - Bear and Finding Criminals的更多相关文章

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

    B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

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

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

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

  4. Codeforces Round #356 (Div. 2)-B

    B. Bear and Finding Criminals 链接:http://codeforces.com/contest/680/problem/B There are n cities in B ...

  5. Codeforces Round #356 (Div. 2)

    A. Bear and Five Cards time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  6. 每日英语:Why Are Items Pricier in China?

    In China, consumers pay nearly $1 more for a latte at Starbucks than their U.S. counterparts. A Cadi ...

  7. Codeforces Round #356 (Div. 1) D. Bear and Chase 暴力

    D. Bear and Chase 题目连接: http://codeforces.com/contest/679/problem/D Description Bearland has n citie ...

  8. Codeforces CF#628 Education 8 F. Bear and Fair Set

    F. Bear and Fair Set time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  9. Codeforces CF#628 Education 8 C. Bear and String Distance

    C. Bear and String Distance time limit per test 1 second memory limit per test 256 megabytes input s ...

随机推荐

  1. git mirror的创建与使用

    please donwload repo mirro as follow steps, thanks 1.mirror server,server IP:192.168.0.123 1.1 -- de ...

  2. Android Eclipse 导入 AS Gradle AAR 库手冊

    序言 这是一篇半技术类文章.众所周知如今Google主推Android Studio开发工具.而Eclipse已经被闲置一阵子了,可是Eclipse项目却还有非常多没有迁移到AS中.而如今一些新的库都 ...

  3. Hadoop实战-Flume之Hello world(九)

    环境介绍: 主服务器ip:192.168.80.128 1.准备apache-flume-1.7.0-bin.tar文件 2.上传到master(192.168.80.128)服务器上 3.解压apa ...

  4. 超实用的 Nginx 极简教程,覆盖了常用场景(转)

    概述 安装与使用 安装 使用 nginx 配置实战 http 反向代理配置 负载均衡配置 网站有多个 webapp 的配置 https 反向代理配置 静态站点配置 搭建文件服务器 跨域解决方案 参考 ...

  5. MongoDB 学习三

    这章我们学习MongoDB的查询操作. Introduction to find find方法用于执行MongoDB的查询操作.它返回collecion中的documents子集,没有添加参数的话它将 ...

  6. System.IO.File类和System.IO.FileInfo类

    1.System.IO.File类 ※文件create, copy,move,SetAttributes,open,exists ※由于File.Create方法默认向所有用户授予对新文件的完全读写. ...

  7. swift-ios开发pod的使用(1)

    MAC安裝CocoaPods   http://www.cnblogs.com/surge/p/4436360.html 请注意我的环境,这个很重要 xcode版本7.3.2   mac 版本OS X ...

  8. AndroidPageObjectTest_Chained.java

    以下代码使用ApiDemos-debug.apk进行测试 //这个脚本用于演示PageFactory的功能:链式注解@AndroidFindBys.@IOSFindBys.具体用法参考页面类的代码. ...

  9. 对私有API提交的注意事项

    1.这个等于堵死了调试断点.关闭就不能断点调试了. 2.对于敏感的函数名要做一个对称加密处理. 防止二进制文件的静态扫描. 3.对于调用私有函数的方法,可以做一个宏定义包装. #define 你的正常 ...

  10. leetcode leetcode 783. Minimum Distance Between BST Nodes

    Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the ...