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 C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramD a = new ProgramD();
            a.main();//実行する

        }

    }

    class ProgramA
    {
        public void main()
        {
            //入力
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);

            //おおきい方を2倍して1引く。ただし、同じときはa+b
            if(a > b)
                Console.WriteLine(2* a -1);
            else if(a < b)
                Console.WriteLine(2 * b - 1);
            else
                Console.WriteLine(a +b);

        }
    }

    class ProgramB
    {
        public void main()
        {

            //入力
            int n = int.Parse(Console.ReadLine());
            string[] h = Console.ReadLine().Split(' ');
            int count = 0;


            //ダメな旅館数を数える
            for(int i = 1;i < n;i++)
                for (int j = 0; j < i; j++)
                {
                    if (int.Parse(h[i]) < int.Parse(h[j]))
                    {
                        count++;
                        break;
                    }
                    
                }

            //答え出力
            Console.WriteLine(n - count);
            

        }
    }

    class ProgramC
    {
        public void main()
        {

            //入力
            string s = Console.ReadLine();

            //候補は101010....か0101010しかないので両方実験してみる
            int count1 = 0;
            int count2 = 0;
            //10101010
            for (int i = 0; i < s.Length; i++)
            {
                if (i % 2 == 0)
                    if (s[i] == '0')
                        count1++;
                if (i % 2 == 1)
                    if (s[i] == '1')
                        count1++;
            }

            //010101010
            for (int i = 0; i < s.Length; i++)
            {
                if (i % 2 == 0)
                    if (s[i] == '1')
                        count2++;
                if (i % 2 == 1)
                    if (s[i] == '0')
                        count2++;
            }

            //答えを出力

            Console.WriteLine(Math.Min(count1,count2));

        }


    }


    class ProgramD
    {
        public void main()
        {

            //入力
            string[] ss = Console.ReadLine().Split(' ');
            int n = int.Parse(ss[0]);
            int k = int.Parse(ss[1]);
            string s = Console.ReadLine();

            List<long> array = new List<long>();
            int flag = 0;

            if (s[0] - '0' == 1)
                flag = 1;

            int count = 1;

            for (int i = 1; i < n; i++)
            {
                if (s[i] != s[i - 1])
                {
                    array.Add(count);
                    count = 1;
                }
                else
                    count++;

                if (i == n - 1)
                    array.Add(count);
            }
            int num = array.Count;
            //ダミーを入れておく
            array.Add(0);
            array.Add(0);

            //入れた数が2*k + flag より少なければ全交換可能
            if (num <= 2 * k + flag)
            {
                Console.WriteLine(s.Length);
                return;
            }

            //kが0回のときは最大の続いているものを出す
            if(k == 0)
            {
                long ans2 = 0;
                if (flag == 0)
                {
                    for (int i = 0; i < num; i = i + 2)
                        ans2 = Math.Max(ans2, array[i + 1]);
                }
                else
                {
                    for (int i = 0; i < num; i = i + 2)
                        ans2 = Math.Max(ans2, array[i]);

                }
                Console.WriteLine(ans2);
                return;

            }

            long sum = 0;
            //それ以外は交換した個数を頭から比較
            for (int i = 0; i < 2 * k + flag; i++)
                sum += array[i];

            long ans = sum;

            for (int i = 2 * k + flag; i < num; i = i + 2)
            {
                if (i == 2 * k + flag)
                {
                    if (flag == 0)
                    {
                        sum -= array[0];
                        sum += array[2 * k];
                        sum += array[2 * k + 1];
                    }
                    else
                    {
                        sum -= array[0];
                        sum -= array[1];
                        sum += array[2 * k + 1];
                        sum += array[2 * k + 2];
                    }


                }
                else
                {
                    sum -= array[i - 2 * k];
                    sum -= array[i - 2 * k - 1];
                    sum += array[i];
                    sum += array[i + 1];
                }

                ans = Math.Max(ans, sum);
            }

            //答を出す
            Console.WriteLine(ans);

        }

    }

    


}