676C.md (1288B)
1 Source: https://codeforces.com/problemset/problem/676/C 2 3 C. Vasya and String 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. 22 23 Vasya can change no more than *k* characters of the original string. What is the maximum beauty of the string he can achieve? 24 25 Input 26 27 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. 28 29 The second line contains the string, consisting of letters 'a' and 'b' only. 30 31 Output 32 33 Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters. 34 35 Examples 36 37 Input 38 39 ``` 40 4 2 41 abba 42 ``` 43 44 Output 45 46 ``` 47 4 48 ``` 49 50 Input 51 52 ``` 53 8 1 54 aabaabaa 55 ``` 56 57 Output 58 59 ``` 60 5 61 ``` 62 63 Note 64 65 In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". 66 67 In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".