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. Kubernetes之网络策略(Network Policy)

    系列目录 概述 Kubernetes要求集群中所有pod,无论是节点内还是跨节点,都可以直接通信,或者说所有pod工作在同一跨节点网络,此网络一般是二层虚拟网络,称为pod网络.在安装引导kubern ...

  2. 三星note3 N900刷机包 4.4.2 ZSUDNE3 官方原汁原味 稳定流畅

    ROM介绍 此ROM基于最新的4.4.2 ZSUDNE3 制作,加入一些必要功能,其它性能基本与官方无差距,各方面感觉都非常不错了.此ROM本人自用,所以制作风格有点个人倾向.不论什么建议或者问题欢迎 ...

  3. GO 入门(一)

    1.下载安装go环境          https://golang.org/dl/ 2.检查环境变量配置情况,安装过程中会自动配置:GOROOT    和    Path 3.建立go工作区,并配置 ...

  4. 九度OJ 1117:整数奇偶排序 (排序)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3174 解决:932 题目描述: 输入10个整数,彼此以空格分隔.重新排序以后输出(也按空格分隔),要求: 1.先输出其中的奇数,并按从大到 ...

  5. wepy原理研究

    像VUE一样写微信小程序-深入研究wepy框架 https://zhuanlan.zhihu.com/p/28700207 wepy原理研究 虽然wepy提升了小程序开发体验,但毕竟最终要运行在小程序 ...

  6. ubuntu 16.04安装Jenkins

    快速安装: sudo wget -q -O - http://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add - sudo ...

  7. appium(7)-Automating mobile gestures

    While the Selenium WebDriver spec has support for certain kinds of mobile interaction, its parameter ...

  8. Struts status

       #status.odd        是否奇数行    #status.count    当前行数    #status.index    当前行的序号,从0开始[#status.count=# ...

  9. ZOJ - 3932 Handshakes 【水】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3932 题意 给出 N 个人,然后 1-N 然后 从 1 - N ...

  10. cURL范例(包括错误输出和详情输出)

    //1.初始化 $ch = curl_init(); //2.设置选项,包括URL curl_setopt($ch, CURLOPT_URL, 'http://www.baidu.com'); cur ...