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 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

int main()
{
 
//  int a, b, c, d, e, X, Y;
  int a, b, c,  d, e,f;
  //  double  c;
//  long long  A[1000001]={};
  int  A[2000001]={};
  int  B[2000001]={};
  int  ans[100003]={};
  int  sum[100003]={};
  int  cnt_flag[100003]={};

  int  L[1003]={};


//  long long  a, b, c, d, X, Y;
//  long long   d, X, Y;
  long long JPY;
  double BTC;
  char s[200001]={};
  char t[200001]={};
  char u[200001]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k,point;
  int point_A=0, point_B=0;
  int flag=0;
//  int flag[10000003]={};
  int tmp=0;
//  int min=1000000;
  int min=10;
  int len=0;
  int cnt=0;
  int cnt0=0;
  int cnt1=0;
  int num=0;
//  double ans=0.0;
//  long long ans=0;
  int max=0;
//  int sum=0;
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
 
  scanf("%d%d", &a, &b);
  scanf("%s", &s);
//  scanf("%d", &max);

  if(s[0]=='0'){
//  printf("%d\n", cnt);
      cnt0++;
//      point_B++;
  } else{
      cnt1++;
      point_A++;
  }

  for(i=1;i<a;i++){
    if(s[i-1]=='0'){
//  printf("%d\n", cnt);
      if(s[i]=='1'){
        cnt1++;
        A[point_A]=cnt0;
        cnt0=0;
        point_A++;
        len++;
      }
      else  cnt0++;
    }
    else{
      if(s[i]=='0'){
        cnt0++;
        B[point_B]=cnt1;
        cnt1=0;
        point_B++;
        len++;
      }
      else cnt1++;
    }
  }
  A[point_A]=cnt0;
  B[point_B]=cnt1;
  point_A=0;
  point_B=0;
  for(i=0;i<(len/2)+1;i++){
    cnt=cnt+B[i-1];
    for(j=i;j<b+i;j++){
      cnt=cnt+B[j]+A[j];
//      printf("i=%d j=%d A=%d B=%d cnt=%d\n",i, j, A[j],B[j], cnt);
    }
    if(cnt>max) max=cnt;
//    printf("i=%d j=%d endA_cnt=%d\n",i, j, cnt);
    cnt=cnt+B[j]-B[i-1];
    if(cnt>max) max=cnt;
//    printf("i=%d j=%d endB_cnt=%d\n",i, j, cnt);
    cnt=0;
  }
  
  printf("%d\n", max);
/*    
    */

//  printf("%s\n",s);
//    else  
  
return 0;
}