645C.md (2284B)
1 Source: https://codeforces.com/problemset/problem/645/C 2 3 C. Enduring Exodus 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 In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his *k* cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of *n* rooms located in a row, some of which are occupied. 22 23 Farmer John wants to book a set of *k* + 1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms *i* and *j* is defined as |*j* - *i*|. Help Farmer John protect his cows by calculating this minimum possible distance. 24 25 Input 26 27 The first line of the input contains two integers *n* and *k* (1 ≤ *k* < *n* ≤ 100 000) — the number of rooms in the hotel and the number of cows travelling with Farmer John. 28 29 The second line contains a string of length *n* describing the rooms. The *i*-th character of the string will be '0' if the *i*-th room is free, and '1' if the *i*-th room is occupied. It is guaranteed that at least *k* + 1 characters of this string are '0', so there exists at least one possible choice of *k* + 1 rooms for Farmer John and his cows to stay in. 30 31 Output 32 33 Print the minimum possible distance between Farmer John's room and his farthest cow. 34 35 Examples 36 37 Input 38 39 ``` 40 7 2 41 0100100 42 ``` 43 44 Output 45 46 ``` 47 2 48 ``` 49 50 Input 51 52 ``` 53 5 1 54 01010 55 ``` 56 57 Output 58 59 ``` 60 2 61 ``` 62 63 Input 64 65 ``` 66 3 2 67 000 68 ``` 69 70 Output 71 72 ``` 73 1 74 ``` 75 76 Note 77 78 In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms. 79 80 In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2. 81 82 In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.