Problem:
Score : 400 points

Problem Statement

N people are arranged in a row from left to right.

You are given a string S of length N consisting of 0 and 1, and a positive integer K.

The i-th person from the left is standing on feet if the i-th character of S is 0, and standing on hands if that character is 1.

You will give the following direction at most K times (possibly zero):

Direction: Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands.

Find the maximum possible number of consecutive people standing on hands after at most K directions.

Constraints

N is an integer satisfying 1 \leq N \leq 10^5.

K is an integer satisfying 1 \leq K \leq 10^5.

The length of the string S is N.

Each character of the string S is 0 or 1.

Input

Input is given from Standard Input in the following format:

N K
S

Output

Print the maximum possible number of consecutive people standing on hands after at most K directions.

Sample Input 1

5 1
00010

Sample Output 1

4

We can have four consecutive people standing on hands, which is the maximum result, by giving the following direction:

Give the direction with l = 1, r = 3, which flips the first, second and third persons from the left.

Sample Input 2

14 2
11101010110011

Sample Output 2

8

Sample Input 3

1 1
1

Sample Output 3

1

No directions are necessary.

Solution in Ruby (2.3.3) (judge verdict: Accepted)

def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

n, k = input_a
s = input_s

a = s.chars
# 0, 1の連続している個数を格納する配列(連続する個数を記録するとき、常に0,1は交互に現れる)
# 最初と最後に必ず1の個数が入るものとする(入力文字列Sがそうでない場合1の個数は0)
counts = []

before = "1"
cnt = 0
# 0, 1が切り替わる度にpush
a.each do |s|
  if s != before
    counts.push(cnt)
    cnt = 1
    before = s
    next
  end
  cnt += 1
end
# 最後の0, 1は切り替わりが行われないため個別にpush
counts.push(cnt)
# 最後が1でなかった場合にpush
if a.last == "0"
  counts.push(0)
end

# 最大K回反転可能であるということは、0のcountを最大K回1のcountに反転できるのと同義である
# countsの左端から右端まで、しゃくとり法で各区間の和を計算することで、最大値が求められる
# 1は反転する必要がないので、区間の長さは2Kとなる→両端が1のとき、1,0の個数は奇数になるので2K+1
# また、連続する1の個数が最大になるのは、両端が0ではなく1になるときであるため、区間は2ずつ進める
# でもしゃくとり法で計算するの混乱する。。。

# 累積和の計算
sums = Array.new(counts.size + 1)
sums[0] = 0
(counts.size).times do |i|
  sums[i + 1] = sums[i] + counts[i]
end

# 左端から2ずつずらして、各区間の総和を累積和から計算する
result = 0
left = 0
while left < sums.size do
  right = left + (k * 2 + 1)
  # rightがはみ出さないように処理
  if right >= sums.size
	right = sums.size - 1
  end
  result = [result, sums[right] - sums[left]].max
  left += 2
end

p result