标签:mes title str ace luci http codeforce origin return
#include<iostream> using namespace std; int main() { long long k,n; cin>>n>>k; string str; cin>>str; long long p=0,ans=0,s=0; for(int i=0;i<n;++i) { if(str[i]==‘b‘) ++p; while(p>k) { if(str[s++]==‘b‘) --p; } ans=max(ans,i-s+1); } p=0; s=0; for(int i=0;i<n;++i) { if(str[i]==‘a‘) ++p; while(p>k) { if(str[s++]==‘a‘) --p; } ans=max(ans,i-s+1); } cout<<ans; return 0; }
尺取法详解:https://blog.csdn.net/lxt_lucia/article/details/81091597
尺取法 C - Vasya and String CodeForces - 676C
标签:mes title str ace luci http codeforce origin return
原文地址:https://www.cnblogs.com/Cnxz/p/12725923.html