High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotesbeauty 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.

string s;
int main()
{
int n,k;
while(cin>>n>>k){
cin>>s;

int start = 0;
int ans = 0;
deque<int> De;
for(int i = 0;i < s.size();i ++){
if(s[i] == 'b') De.push_back(i);
if(De.size() > k){
start = De.front()+1;
De.pop_front();
}
ans = max(ans,i-start+1);
}
De.clear();
start = 0;
for(int i = 0;i < s.size();i ++){
if(s[i] == 'a') De.push_back(i);
if(De.size() > k){
start = De.front()+1;
De.pop_front();
}
ans = max(ans,i-start+1);
}
cout<<ans<<endl;
}
return 0;
}

双端队列 C. Vasya and String的更多相关文章

  1. 补番计划 (长沙理工大学第十一届程序设计竞赛)(双端队列+set容器+string)

    补番计划 Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Submissi ...

  2. 双端队列(单调队列)poj2823 区间最小值(RMQ也可以)

    Sliding Window Time Limit: 12000MS   Memory Limit: 65536K Total Submissions: 41844   Accepted: 12384 ...

  3. P - The Shortest Path in Nya Graph-hdu4725(双端队列+拆点)

    题意:有N个点和N层..一层有X个点(0<=X<=N).两邻两层间有一条路花费C.还有M条小路在两个点之间.问从第一个点走到第N个点最短路是多少... 可以考虑在每一层增加一个点,这个点到 ...

  4. 《算法实战策略》-chaper19-队列、栈和双端队列

    对于计算机专业的学生来说,他们一定会很熟悉一句话:程序设计 = 算法 + 数据结构.而根据笔者的理解,所谓程序设计其实就是为了编程解决实际问题,所谓算法是一种解决问题某种思维的方法,但是思维需要得到编 ...

  5. python 下的数据结构与算法---4:线形数据结构,栈,队列,双端队列,列表

    目录: 前言 1:栈 1.1:栈的实现 1.2:栈的应用: 1.2.1:检验数学表达式的括号匹配 1.2.2:将十进制数转化为任意进制 1.2.3:后置表达式的生成及其计算 2:队列 2.1:队列的实 ...

  6. Java 模拟队列(一般队列、双端队列、优先级队列)

    队列: 先进先出,处理类似排队的问题,先排的.先处理,后排的等前面的处理完了,再处理 对于插入和移除操作的时间复杂度都为O(1).从后面插入,从前面移除 双端队列: 即在队列两端都能够insert和r ...

  7. C++ STL 双端队列deque详解

    一.解释 Deque(双端队列)是一种具有队列和栈的性质的数据结构.双端队列的元素可以从两端弹出,其限定插入和删除操作在表的两端进行. 二.常用操作: 1.头文件 #include <deque ...

  8. [Swift]LeetCode641. 设计循环双端队列 | Design Circular Deque

    Design your implementation of the circular double-ended queue (deque). Your implementation should su ...

  9. POJ3662 SPFA//二分 + 双端队列最短路

    https://cn.vjudge.net/problem/12427/origin 题意:求1到N第K + 1大条边权最小的路径 首先想到dp递推,dp[x][y]表示到x这个点经过y条免费边的最小 ...

随机推荐

  1. Re-ranking Person Re-identification with k-reciprocal Encoding

    Re-ranking Person Re-identification with k-reciprocal Encoding Abstract In this paper, we propose a ...

  2. python+opencv实现车牌定位

    写在前面 HIT大三上学期视听觉信号处理课程中视觉部分的实验三,经过和学长们实验的对比发现每一级实验要求都不一样,因此这里标明了是2019年秋季学期的视觉实验三. 由于时间紧张,代码没有进行任何优化, ...

  3. ZOJ Problem Set - 1010

    算法:已知多边形各顶点坐标,求多边形面积的公式 http://www.cnblogs.com/FleetingTime/p/3849957.html http://www.mathchina.net/ ...

  4. 模型预测控制 MPC

    使用MPC的原因:

  5. [Agc029C]Lexicographic constraints_进制_二分答案_贪心

    Lexicographic constraints 题目链接:https://atcoder.jp/contests/agc029/tasks/agc029_c 数据范围:略. 题解: 二分是显然的, ...

  6. [转帖]redis监控工具汇总

    redis监控工具汇总 https://www.cnblogs.com/felixzh/p/11170143.html redis-stat redis-stat是一个比较有名的redis指标可视化的 ...

  7. mysql-事务总结

    目录 事务基本概念 事务的定义 使用事务 自动提交 特殊操作 ACID特性及其原理 原子性(A) 持久性 (D) 隔离性 脏读.不可重复读和幻读 事务隔离级别 mysql事务日志 redo log 定 ...

  8. 【AtCoder】CODE FESTIVAL 2016 qual C

    CODE FESTIVAL 2016 qual C A - CF -- #include <bits/stdc++.h> #define fi first #define se secon ...

  9. Windows32或64位下载安装配置Spark

    [学习笔记] Windows 32或64位下载安装配置Spark:1)下载地址:http://spark.apache.org/downloads.html 马克-to-win @ 马克java社区: ...

  10. 坦克大战--Java类型

    写在前面       Java编译器下载教程(真的良心):https://blog.csdn.net/Haidaiya/article/details/81230636 本项目为本人独自制作,请各位尊 ...