codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

680B.md (2555B)


      1 Source: https://codeforces.com/problemset/problem/680/B
      2 
      3 B. Bear and Finding Criminals
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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*|.
     22 
     23 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.
     24 
     25 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.
     26 
     27 You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD.
     28 
     29 Input
     30 
     31 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.
     32 
     33 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.
     34 
     35 Output
     36 
     37 Print the number of criminals Limak will catch.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 6 3  
     45 1 1 1 0 1 0
     46 ```
     47 
     48 Output
     49 
     50 ```
     51 3
     52 ```
     53 
     54 Input
     55 
     56 ```
     57 5 2  
     58 0 0 0 1 0
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 1
     65 ```
     66 
     67 Note
     68 
     69 In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.
     70 
     71  ![](https://espresso.codeforces.com/74445df6818d0a935b3cc471d18d64101be6f281.png) 
     72 
     73 Using the BCD gives Limak the following information:
     74 
     75 * There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city.
     76 * 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.
     77 * 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.
     78 * There are zero criminals for every greater distance.
     79 
     80 So, Limak will catch criminals in cities 1, 3 and 5, that is 3 criminals in total.
     81 
     82 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.
     83 
     84  ![](https://espresso.codeforces.com/c2bacc2aceaabacc98cc0dba179bc344f02aae9f.png)