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 Haskell (GHC 7.10.3) (judge verdict: Accepted)

{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C
import Data.Vector.Unboxed (Vector, (!))
import qualified Data.Vector.Unboxed as U
import Data.Vector.Unboxed.Mutable (unsafeRead, unsafeWrite)
import qualified Data.Vector.Unboxed.Mutable as UM

main :: IO ()
main = do
  [n, k] <- readInts
  s <- C.getLine
  print $ solve n k s

{-
000110100011110
K+1 個の 1 の塊をつなげられる
000 11 0 1 000 1111 0
K=1の時
000 11 0 1 [000] 1111 0
000 11 0 1 111 1111 0
が最大となる
連続する数字の数を次のように格納する
3 2 1 1 3 4 1
一番左が0の時は先頭に0を追加する
0 3 2 1 1 3 4 1
また後ろには0を追加する(最終的に奇数になっていれば不要だが常に追加してよい)
0 3 2 1 1 3 4 1 0
として、連続するK+2個が最大になるものを探していく
K=1なら
[0 3 2] 1 1 3 4 1
0 3 [2 1 1] 3 4 1
0 3 2 1 [1 3 4] 1
-}

solve n k s = getMax preProcess
  where
    getMax :: Vector Int -> Int
    getMax v = if (2 * k + 1) >= len then U.sum v else maximum $ getMaxSub 0 (U.sum $ U.take 2 v) firstK2Sum []
      where
        getMaxSub i p cnt xs =
          if (i + 2 * k + 2) >= len
            then (cnt:xs)
            else getMaxSub (i + 2) first2Sum (cnt - p + next2Sum) (cnt:xs)
          where
            next2Sum = (v U.! (i + 2 * k + 1) + v U.! (i + 2 * k + 2))
            first2Sum = (v U.! (i + 2) + v U.! (i + 3))
        firstK2Sum = U.sum $ U.take (2 * k + 1) v
    len = U.length preProcess
    preProcess :: Vector Int
    preProcess = U.fromList $ if C.index s 0 == '0'
      then preProcessSub 1 '0' 1 [0]
      else preProcessSub 1 '1' 1 []
    preProcessSub i prev cnt xs = if i >= n
      then reverse (0:cnt:xs)
      else if c == prev
        then preProcessSub (i + 1) prev (cnt + 1) xs
        else preProcessSub (i + 1) c 1 (cnt:xs)
      where
        c = C.index s i

vectest :: Vector Int -> Vector Int
vectest input = U.create $ do
  v <- UM.replicate 1000 0
  forM_ [0 .. 999] (\i -> do
    let e = input ! i
    unsafeWrite v i e
    )
  return v

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine