当前位置:网站首页>CF676C Vasya and String
CF676C Vasya and String
2022-06-26 13:57:00 【__ LazyCat__】
Ideas
Similar to the simple rule taking method , Separate the sequence with a,b To calculate .
To choose a Come on , We treat each b assignment 1 Representative needs 1 The price to get 1 The value of , Yes a The price is 0, This problem turns into a simple rule taking method .( At the greatest cost k The longest number of sequences can be obtained even if the answer ). Then on b Do the same thing , The answer is to take the maximum of two operations .
Code
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1e5+5;
int a[maxn];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int cnt=0,n,k;
string ss;
cin>>n>>k>>ss;
int ans=0;
int s=1,w=0,sum=0;
a[1]=ss[0]=='a'?1:0;// Assign a value to the initial cost
for(int i=1;i<n;i++){
a[i+1]=(ss[i]=='a'?1:0);// Pretreatment cost
}
for(int i=1;i<=n;i++){
// Simple ruler method
sum++;w+=a[i];
while(s<=i&&w>k){
// cost w, Maximum price to pay k
sum--;w-=a[s++];
}
ans=max(ans,sum);
}
a[1]=ss[0]=='b'?1:0;// ditto
for(int i=1;i<n;i++){
a[i+1]=(ss[i]=='b'?1:0);
}
s=1,sum=0,w=0;
for(int i=1;i<=n;i++){
sum++;w+=a[i];
while(s<=i&&w>k){
sum--;w-=a[s++];
}
ans=max(ans,sum);
}
cout<<ans<<endl;
return 0;
}
边栏推荐
- 泰山OFFICE技术讲座:使用字体粗体的四种情形
- Es6: iterator
- Detailed practical sharing, two hours of funny videos after work, earning more than 7000 a month
- Reprint - easy to use wechat applet UI component library
- d的is表达式
- [proteus simulation] Arduino uno key start / stop + PWM speed control DC motor speed
- d检查类型是指针
- GC is not used in D
- Lamp compilation and installation
- ES6 module
猜你喜欢

HW蓝队溯源流程详细整理

ES基于Snapshot(快照)的数据备份和还原

LAMP编译安装

ES6:Map

Some conclusions about Nan

Nexys A7开发板资源使用技巧

MongoDB系列之Window环境部署配置

Echart stack histogram: add white spacing effect setting between color blocks

33、使用RGBD相机进行目标检测和深度信息输出

Wechat applet -picker component is repackaged and the disabled attribute is added -- below
随机推荐
7-3 minimum toll
【HCSD应用开发实训营】一行代码秒上云评测文章—实验过程心得
Wechat applet -picker component is repackaged and the disabled attribute is added -- below
创建一个自己的跨域代理服务器
Mediapipe gestures (hands)
Memory considerations under bug memory management
ES6:Map
PHP非对称加密算法(RSA)加密机制设计
Global variable vs local variable
DataGrip配置的连接迁移
Ubuntu installation and configuration PostgreSQL (18.04)
防火墙介绍
VTK 圆柱体的生成与渲染
ICML 2022 | limo: a new method for rapid generation of targeted molecules
网络远程访问的方式使用树莓派
7-1 n queen problem
Common operation and Principle Exploration of stream
Here document interaction free and expect automatic interaction
awk工具
D中不用GC