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 Rust (1.15.1) (judge verdict: Accepted)

#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(unknown_lints)]
#![allow(unused_variables)]
#![allow(unused_must_use)]
#![allow(unused_mut)]
#![allow(dead_code)]
#![allow(unused_assignments)]

use std::collections::HashMap;
use std::io::{stderr, Write};
use std::process::exit;

macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: i32,
        k: i32,
        s: String
    }
    let mut s: Vec<char> = s.chars().collect();

    //let mut n: i32 = 4;
    //let mut k: i32 = 1;
    //let mut s: Vec<char> = Vec::new();
    //let mut s: Vec<char> = vec!['0', '0', '1', '0', '1', '1'];

    let mut l: usize = 0;
    let s_len = s.len();
    let mut sums: Vec<usize> = Vec::new();
    let mut r: usize = 1;
    let i = 0;
    for i in 0..k {
        while r < s_len && s[r] == s[l] {
            r = r + 1;
        }
        while r < s_len && s[r] != s[l] {
            r = r + 1;
        }
        while r < s_len && s[r] == s[l] {
            if s[r] == '1' {
                r = r + 1;
            } else if i == k-1 {
                break;
            } else {
                r = r + 1;
            }
        }
        r = r - 1;
        debug!(l);
        debug!(r);
    }
    let sum = r - l + 1;
    debug!(l);
    debug!(r);
    debug!(sum);
    sums.push(sum);
    while r < s_len-1 {
        let start = s[l];
        while s[l] == start && l < s_len-1 {
            l = l + 1;
        }
        while start != '0' && s[l] != start && l < s_len-1 {
        //while s[l] != start && l < s_len-1 {
            l = l + 1;
        }
        if r < s_len {
            r = r + 1;
        }
        if start == '0' {
            while r < s_len && s[r] == '1' {
                r = r + 1;
            }
            while r < s_len && s[r] == '0' {
                r = r + 1;
            }
            while r < s_len && s[r] == '1' {
                r = r + 1;
            }
        } else {
            while r < s_len && s[r] != start {
                r = r + 1;
            }
            if start == '1' {
                while r < s_len && s[r] == start {
                    r = r + 1;
                }
            }
        }
        r = r - 1;
        let sum = r - l + 1;
        debug!(l);
        debug!(r);
        debug!(sum);
        sums.push(sum);
    }
    let max = sums.iter().max();
    match max {
        Some(max) => {
            println!("{}", max);
        },
        None => {}
    }
}