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++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
ll k (ll a){
    a--;
    ll ans =0;
    while(a != 0){
        ans += a;
        a--;
        
    }
    return ans;
}


char grid[505][505];
int h,w;
pair<int, int> st,en;
int score[505][505];

void bfs(int x, int y){
    queue<pair<int, int>> Q;
    score[x][y] = 0;

    Q.push(make_pair(x,y));

    while(!Q.empty()){
        pair<int ,int> p = Q.front(); Q.pop();
        int hh = p.second;
        int ww = p.first;

        REP(i,4){
            int nx = ww + dr[i];
            int ny = hh + dc[i];

            if(nx < 0 || w <= nx || ny < 0 || h <= ny){
                continue;
            }

            if(grid[nx][ny] == '#' && score[nx][ny] > (score[x][y]+1)){
                Q.push(make_pair(nx,ny));
                score[nx][ny] = score[x][y] +1;
            }

            if(score[nx][ny] > (score[x][y] +1)  && grid[nx][ny] != '#'){
                Q.push(make_pair(nx,ny));
                score[nx][ny] = score[x][y];
            }
        }
    }
}

int n,m;
int a[1500];

int dfs(int x,int cnt,int i){
    if(cnt == 0) return x;
    if(x >= m) return 0;

    x = max(x,dfs(x+a[i],cnt-1,i+1));
    return x;
}

int main(){
    ll n,k;
    string s;
    cin >> n >>k >>s;
    if(n == 1){
            cout << 1 <<endl;
    }
    vector<int> vec;
    vec.push_back(0);
    int cnt=0;
    REP(i,s.size()-1){
        if(s[i] == '1' && s[i+1] == '1'){
            cnt ++;
        }else if(s[i] == '1'){
            cnt ++;
            vec.push_back(cnt);
            cnt = 0;
        }else if(s[i] == '0' && s[i+1]=='0'){
            cnt++;
        }else{
            cnt++;
            cnt *= -1;
            vec.push_back(cnt);
            cnt =0;
        }
    }
    if(cnt > 0){
        if(s[s.size()-1] == '0'){
            cnt++;
            cnt *= -1;
            vec.push_back(cnt);
            cnt =0;
        }else{
            cnt ++;
            vec.push_back(cnt);
        
            cnt = 0;
        }
    }else{
        if(s[s.size()-1] == '0'){
            vec.push_back(-1);
        }else{
            vec.push_back(1);
        }
    }
    
    vec.push_back(0);
    REP(i,k){
        int mm=0,x=0,mi=0;
        REP(j,vec.size()-1){
            if(vec[j] < 0){
                
                x = (vec[j]*-1);
                x+= vec[j-1];
                x+= vec[j+1];
                if(mm < x){
                    mm = x;
                    mi = j;
                    x = 0;
                }
            }
        }
        vec[mi-1] =mm;
        
       vec.erase(vec.begin()+mi,vec.begin()+mi+2);
    }

    int ans = 0;
    REP(i,vec.size()){
        ans = max(ans,vec[i]);
    }
    cout << ans <<endl;
    
}