303330: CF645C. Enduring Exodus

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Enduring Exodus

题意翻译

一个农夫带着 $k$ 头牛去住店,(人一间,每牛一间)。 已知该旅店共有 $n$ 间房,其中部分房间已有人住,房间住宿情况由 $01$ 串表示,$0$ 表示空,$1$ 表示已有人住,剩余房间足够容纳 $k+1$ 头牛和人。 为了保障牛的安全,希望人住的房间离最远的牛的房间位置尽量小,输出最小距离。 $1\leq k < n\leq 10^5$。

题目描述

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. 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.

输入输出格式

输入格式


The first line of the input contains two integers $ n $ and $ k $ ( $ 1<=k&lt;n<=100000 $ ) — the number of rooms in the hotel and the number of cows travelling with Farmer John. 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.

输出格式


Print the minimum possible distance between Farmer John's room and his farthest cow.

输入输出样例

输入样例 #1

7 2
0100100

输出样例 #1

2

输入样例 #2

5 1
01010

输出样例 #2

2

输入样例 #3

3 2
000

输出样例 #3

1

说明

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. 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 $ . 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 $ .

Input

题意翻译

一个农夫带着 $k$ 头牛去住店,(人一间,每牛一间)。 已知该旅店共有 $n$ 间房,其中部分房间已有人住,房间住宿情况由 $01$ 串表示,$0$ 表示空,$1$ 表示已有人住,剩余房间足够容纳 $k+1$ 头牛和人。 为了保障牛的安全,希望人住的房间离最远的牛的房间位置尽量小,输出最小距离。 $1\leq k < n\leq 10^5$。

加入题单

算法标签: