CF676C.Vasya and String

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?

高中生瓦西娅生日时收到了一个长度为 nn 的字符串作为礼物。该字符串仅由字母 'a' 和 'b' 组成。瓦西娅将字符串的“美丽值”定义为:由相同字母组成的最长子串(连续子序列)的长度。

瓦西娅最多可以修改原字符串中的 kk 个字符。他所能达到的最大美丽值是多少?

输入格式

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.

输入的第一行包含两个整数 nn 和 kk(1≤n≤100 0001 \leq n \leq 100\,000,0≤k≤n0 \leq k \leq n)—— 分别表示字符串的长度以及最多可修改的字符个数。

第二行包含一个仅由字母 'a' 和 'b' 组成的字符串。

输出格式

Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.

输出唯一的整数——Vasya 通过最多修改 k 个字符所能达到的字符串的最大美观度。

输入输出样例

  • 输入#1

    4 2
    abba

    输出#1

    4
  • 输入#2

    8 1
    aabaabaa

    输出#2

    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".

在第一个样例中,Vasya 可以得到字符串 “aaaa” 和 “bbbb”。

在第二个样例中,最优解可通过字符串 “aaaaabaa” 或字符串 “aabaaaaa” 得到。

输入解题思路,AI测评打分。不知道怎么写?

首页