题目链接:http://codeforces.com/contest/676/problem/C
原题题解链接:http://www.cnblogs.com/vincentX/p/5405468.html
太菜了,昨晚光想着分块,却没考虑做尺取的时候,对于不需要变化的,那对计数器到k不做贡献。早上恍然大悟,5min改出来了…鶸一个。
/*
━━━━━┒ギリギリ♂ eye!
┓┏┓┏┓┃キリキリ♂ mind!
┛┗┛┗┛┃\○/
┓┏┓┏┓┃ /
┛┗┛┗┛┃ノ)
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┃┃┃┃┃┃
┻┻┻┻┻┻
*/
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define fr first
#define sc second
#define cl clear
#define BUG puts("here!!!")
#define W(a) while(a--)
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%I64d", &a)
#define Rs(a) scanf("%s", a)
#define Cin(a) cin >> a
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f7f, sizeof(a))
#define pi 3.14159265359
#define RT return
#define lowbit(x) x & (-x)
#define onenum(x) __builtin_popcount(x)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef map<string, int> msi;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb; const int maxn = ;
int n, k;
int a[maxn];
char s[maxn]; int main() {
// FRead();
while(~Rint(n) && ~Rint(k)) {
Rs(s+);
For(i, , n+) {
if(s[i] == 'a') a[i] = ;
else a[i] = ;
}
int l = , r = ;
int cur = , ans = ;
while() {
if(r > n) break;
while(r <= n && cur <= k) {
if(a[r] == ) {
if(cur == k) break;
cur++;
}
r++;
}
if(r - l > ans) ans = r - l;
while(l <= r && a[l] == ) l++;
cur--;
l++;
}
int ret = ans;
For(i, , n+) {
if(s[i] == 'a') s[i] = 'b';
else s[i] = 'a';
}
For(i, , n+) {
if(s[i] == 'a') a[i] = ;
else a[i] = ;
}
l = , r = ; cur = , ans = ;
while() {
if(r > n) break;
while(r <= n && cur <= k) {
if(a[r] == ) {
if(cur == k) break;
cur++;
}
r++;
}
if(r - l > ans) ans = r - l;
while(l <= r && a[l] == ) l++;
cur--;
l++;
}
printf("%d\n", max(ans, ret));
}
RT ;
}