B. Bear and Finding Criminals
2016-06-15 18:22
288 查看
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 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.
Examples
input
output
input
output
Note
In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.
Using the BCD gives Limak the following information:
There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city.
There is one criminal at distance 1 from the third city — Limak doesn't know if a criminal is in the second or fourth city.
There are two criminals at distance 2 from the third city — Limak is sure that there is one criminal in the first city and one in the fifth
city.
There are zero criminals for every greater distance.
So, Limak will catch criminals in cities 1, 3 and 5,
that is 3 criminals in total.
In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance 2from Limak's city. There is
only one city at distance 2 so Limak is sure where a criminal is.
解题说明:此题要求确定位置查找,可以先进行遍历找到左右都标记为1的字段,然后统一。
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 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.
Examples
input
6 3 1 1 1 0 1 0
output
3
input
5 2 0 0 0 1 0
output
1
Note
In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.
Using the BCD gives Limak the following information:
There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city.
There is one criminal at distance 1 from the third city — Limak doesn't know if a criminal is in the second or fourth city.
There are two criminals at distance 2 from the third city — Limak is sure that there is one criminal in the first city and one in the fifth
city.
There are zero criminals for every greater distance.
So, Limak will catch criminals in cities 1, 3 and 5,
that is 3 criminals in total.
In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance 2from Limak's city. There is
only one city at distance 2 so Limak is sure where a criminal is.
解题说明:此题要求确定位置查找,可以先进行遍历找到左右都标记为1的字段,然后统一。
相关文章推荐
- 依然排序
- Python+Django+Bootstrap 框架环境搭建
- Java多线程19:定时器Timer
- android image不显示
- Android 获取联系人电话号码
- 使用shell区分Android软硬重启问题
- iOS开发常用国外网站清单
- Mac开机启动登录之前启动VmWare 解决方案
- Java多线程18:线程池
- Activemq 常见的一些问题 心得
- 数据结构之栈的基本操作
- Mybatis Mapper xml映射配置知识总结
- Effective C++ 笔记二构造/析构/赋值运算
- 启程
- Java多线程17:中断机制
- springmvc入门基础之注解和参数传递
- java 求md5值,即md5加密算法
- shell笔记2 tput
- Java多线程16:线程组
- Java多线程15:Queue、BlockingQueue以及利用BlockingQueue实现生产者/消费者模型