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 ;
}

最新文章

  1. 每天一个 Linux 命令(20):find命令之exec
  2. [转]几种常见SQL分页方式
  3. InvocationHandler
  4. html_entity_decode() 函数
  5. Json数据解析在Unity3d中的应用
  6. UESTC 30 &amp;&amp;HDU 2544最短路【Floyd求解裸题】
  7. NPOI 2.0 教程
  8. adSage :2013年教育行业搜索引擎投放分析报告
  9. 排查线上问题常用的几个Linux命令
  10. npm脚本探析
  11. JavaWeb--简单分页技术
  12. 初识thinkphp(2)
  13. 基于.htaccess的Web Shell工具htshells
  14. k8s的容器监测探针
  15. zabbix安装配置2
  16. Thymeleaf学习记录(5)--运算及表单
  17. A.Activity planning
  18. mysql case when &amp; concat &amp; SUBSTRING_INDEX &amp; not &amp; having 使用的小case
  19. Linux利器strace
  20. 小程序开发-7-访问api数据与ES6在小程序中的应用

热门文章

  1. svn 安装 、使用(2)
  2. [AHOI 2006][BZOJ 1269]文本编辑器editor
  3. JSBinding + SharpKit / 实战:转换 Stealth
  4. 关于$.ajax中data字段的整理--包括json转换和spring注解
  5. Linux启动新进程的三种方法
  6. C# 中的EventHandler
  7. shell流程控制语句
  8. 【svn】 SVN错误:Attempted to lock an already-locked dir
  9. [oracle] 解决X64操作系统PL/SQL连接报错问题 make sure you have the 32 bits oracle client installed
  10. Add LUN to ASM in Linux