High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotesbeauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
4 2 abba
4
8 1 aabaabaa
5
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
尺取法
/* ***********************************************
Author : ryc
Created Time : 2016-08-03 Wednesday
File Name : E:\acmcode\codeforces\354div2C.cpp
Language : c++
Copyright 2016 ryc All Rights Reserved
************************************************ */
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<list>
#include<vector>
#include<queue>
#include<map>
using namespace std;
const int maxn=100010;
char str[maxn];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
scanf("%s",str+1);
int ans=0,temp=m,l=1;
for(int i=1;i<=n;++i){
if(str[i]=='b')temp--;
while(temp<0){if(str[l++]=='b')temp++;}
ans=max(ans,i-l+1);
}temp=m;l=1;
for(int i=1;i<=n;++i){
if(str[i]=='a')temp--;
while(temp<0){if(str[l++]=='a')temp++;}
ans=max(ans,i-l+1);
}
printf("%d\n",ans);
return 0;
}