CodeForces 676C Vasya and String

4人阅读 评论(0) 收藏 举报
分类:

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?

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

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

Examples
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+7;
char s[N];
int n,k;
int check(char tmp)
{
    int l=0,r=0,cnt=0,ma=0;
    while(r<n)
    {
        if(s[r]!=tmp)cnt++;
        r++;
        while(cnt>k&&l<=r)
        {
             if(s[l]!=tmp)cnt--;
            l++;
        }
        while(r<n&&s[r]==tmp)
            r++;
        ma=max(r-l,ma);
    }
    return ma;
}
int main()
{
    scanf("%d%d%s",&n,&k,s);
    printf("%d\n",max(check('a'),check('b')));
}
查看评论

Codeforces 676C Vasya and String (两点法)

Codeforces 676C Vasya and String (两点法)
  • Tc_To_Top
  • Tc_To_Top
  • 2016-05-26 14:30:04
  • 1201

Codeforces 676C - Vasya and String 详解(二分前缀和+尺取两种写法)

C. Vasya and String time limit per test  1 second memory limit per test  256 megabytes ...
  • qq_34374664
  • qq_34374664
  • 2017-01-16 23:35:10
  • 514

codeforces 676C Vasya and String

Vasya and String time limit per test 1 second memory limit per test 256 megabytes input ...
  • SCAU_BIN
  • SCAU_BIN
  • 2016-05-27 00:43:03
  • 620

Codeforces 676C Vasya and String

题目链接:http://codeforces.com/problemset/problem/676/C 题意:给一个只含有ab的字符串,最多修改k个字符使得一段连续字符串只包含一种字符的长度...
  • chy20142109
  • chy20142109
  • 2016-06-05 17:15:59
  • 159

codeforces 676C Vasya and String (尺取法)

题目:http://codeforces.com/problemset/problem/676/C 代码:#include using namespace std; const int maxn=1...
  • qq_32473657
  • qq_32473657
  • 2016-05-26 21:52:21
  • 122

Codeforces 676C Vasya and String 尺取法

C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes input sta...
  • Turne
  • Turne
  • 2016-06-06 21:20:40
  • 212

Codeforces 624C:Graph and String 二分图染色

C. Graph and String time limit per test 2 seconds memory limit per test 256 megabytes ...
  • u010885899
  • u010885899
  • 2016-03-02 15:40:19
  • 682

codeforces 676C Vasya and String(尺取法)

C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standar...
  • wchhlbt
  • wchhlbt
  • 2016-06-01 21:42:41
  • 486

(尺取法)Codeforces 676C - Vasya and String

原题链接:http://codeforces.com/problemset/problem/676/C题意:有一串a和b组成的字符串,要求最多改k的字母的情况下,最长的相同子串。 例如k=2:abb...
  • HradStone
  • HradStone
  • 2016-08-04 09:00:31
  • 187

codeforces 676C (尺取法)

C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes ...
  • morejarphone
  • morejarphone
  • 2016-05-26 10:34:19
  • 394
    个人资料
    等级:
    访问量: 5742
    积分: 546
    排名: 9万+
    最新评论