当前位置:网站首页>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;
}
边栏推荐
- 虫子 运算符重载的一个好玩的
- 12 SQL optimization schemes summarized by old drivers (very practical)
- What is the use of index aliases in ES
- D中不用GC
- 7-2 a Fu the thief
- 【HCSD应用开发实训营】一行代码秒上云评测文章—实验过程心得
- Bug STL string
- Gurivat sprint Harbour Exchange listed: created “multiple first”, received 900 million yuan Investment from IDG capital
- Connection migration for DataGrid configuration
- hands-on-data-analysis 第三单元 模型搭建和评估
猜你喜欢

Reprint - easy to use wechat applet UI component library

Nexys A7开发板资源使用技巧

Design of simple digital circuit traffic light

Pytorch based generation countermeasure Network Practice (7) -- using pytorch to build SGAN (semi supervised GaN) to generate handwritten digits and classify them

Awk tools

8.Ribbon负载均衡服务调用

2021-10-09

What is the use of index aliases in ES

Wechat applet -picker component is repackaged and the disabled attribute is added -- below

古瑞瓦特沖刺港交所上市:創下“多個第一”,獲IDG資本9億元投資
随机推荐
ICML 2022 | LIMO: 一种快速生成靶向分子的新方法
ES中索引别名(alias)的到底有什么用
微信小程序注册指引
[node.js] MySQL module
7-2 picking peanuts
古瑞瓦特沖刺港交所上市:創下“多個第一”,獲IDG資本9億元投資
NVM installation tutorial
Select tag - uses the default text as a placeholder prompt but is not considered a valid value
Learn how to develop owl components by hand (7): practical use of owl projects
虫子 内存管理 下 内存注意点
虫子 内存管理 上
程序员必备,一款让你提高工作效率N倍的神器uTools
array
三维向量的夹角
hands-on-data-analysis 第三单元 模型搭建和评估
12 SQL optimization schemes summarized by old drivers (very practical)
GEE——全球人类居住区网格数据 1975-1990-2000-2014
Variable declaration of typescript
Tips for using nexys A7 development board resources
【HCSD应用开发实训营】一行代码秒上云评测文章—实验过程心得