#include <iostream> #include <cstdio> #include <algorithm> using namespace std; int count_max_len(char f,const string& s,int m,int n); int main() { int m, n; string s; cin >> n >> m >> s; if (m == n)cout << n; else cout<< max(count_max_len('a',s,m,n),count_max_len('b',s,m,n)); return 0; } int count_max_len(char f, const string& s,int m,int n) { int max_len = m, ca = 0; int pl = 0, pr = 0; while (pr < n) { if (s[pr] == f) { ca++; if (ca == (m + 1)) { ca--; max_len = max(max_len, pr - pl); while (pl <= pr && s[pl] != f) { pl++; } pl++; } } pr++; } return max_len; } // 64 位输出请用 printf("%lld")