首页 技术 正文
技术 2022年11月16日
0 收藏 492 点赞 4,583 浏览 1446 个字

B. Bear and Finding Criminalstime 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.

Examplesinput

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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,078
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,553
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,402
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,177
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,814
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898