CF680B.Bear and Finding Criminals
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
熊国共有 n 座城市,编号为 1 到 n。这些城市排成一条长直线。城市 i 与城市 j 之间的距离等于 ∣i−j∣。
Limak 是一名警察,居住在城市 a。他的工作是抓捕罪犯。这很困难,因为他不知道罪犯位于哪些城市。不过,他确知:每座城市中至多有一名罪犯。
Limak 将使用一种 BCD(熊族罪犯探测器)。BCD 会告诉 Limak:对于从城市 a 出发的每一个距离值,该距离处的所有城市中罪犯的总人数。此后,Limak 就能抓捕那些他确定一定有罪犯的城市中的罪犯。
你已知罪犯实际所在的城市。请计算:Limak 在使用 BCD 后,总共能抓捕多少名罪犯。
输入格式
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 _t_1, _t_2, ..., t__n (0 ≤ t__i ≤ 1). There are t__i criminals in the i-th city.
输入的第一行包含两个整数 n 和 a(1 ≤ a ≤ n ≤ 100)——分别表示城市的数量以及Limak所在城市的编号。
第二行包含 n 个整数 t1, t2, ..., tn(0 ≤ ti ≤ 1)。第 i 个城市中有 ti 名罪犯。
输出格式
Print the number of criminals Limak will catch.
输出Limak将抓获的罪犯数量。
输入输出样例
输入#1
6 3 1 1 1 0 1 0
输出#1
3
输入#2
5 2 0 0 0 1 0
输出#2
1
说明/提示
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 2 from Limak's city. There is only one city at distance 2 so Limak is sure where a criminal is.

在第一个样例中,共有六座城市,Limak 居住在第三座城市(如下图中的蓝色箭头所示)。罪犯位于标为红色的城市中。

使用 BCD,Limak 获得以下信息:
- 距离第三座城市为 0 的位置有 1 名罪犯——Limak 确定该罪犯就在第三座城市中。
- 距离第三座城市为 1 的位置有 1 名罪犯——Limak 不确定该罪犯是在第二座城市还是第四座城市。
- 距离第三座城市为 2 的位置有 2 名罪犯——Limak 确定其中一名罪犯在第一座城市,另一名在第五座城市。
- 对于所有更大的距离,罪犯数量均为 0。
因此,Limak 将在第 1、3 和 5 号城市抓获罪犯,共 3 名罪犯。
在第二个样例(如下图所示)中,BCD 告知 Limak:距离他所在城市为 2 的位置有 1 名罪犯。而距离为 2 的城市仅有一座,因此 Limak 能准确确定该罪犯的位置。

输入解题思路,AI测评打分。不知道怎么写?