CoderForces999C-Alphabetic Removals
2 seconds
256 megabytes
standard input
standard output
You are given a string ss consisting of nn lowercase Latin letters. Polycarp wants to remove exactly kk characters (k≤nk≤n) from the string ss. Polycarp uses the following algorithm kk times:
- if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item;
- if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item;
- ...
- remove the leftmost occurrence of the letter 'z' and stop the algorithm.
This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly kk times, thus removing exactly kk characters.
Help Polycarp find the resulting string.
The first line of input contains two integers nn and kk (1≤k≤n≤4⋅1051≤k≤n≤4⋅105) — the length of the string and the number of letters Polycarp will remove.
The second line contains the string ss consisting of nn lowercase Latin letters.
Print the string that will be obtained from ss after Polycarp removes exactly kk letters using the above algorithm kk times.
If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break).
15 3
cccaabababaccbc
cccbbabaccbc
15 9
cccaabababaccbc
cccccc
1 1
u
AC代码为:
#include<bits/stdc++.h>
using namespace std;
const int maxn=4e5+10;
struct Node{
int id,temp;
char c;
} node[maxn];
bool cmp1(Node a,Node b)
{
return a.c==b.c? a.id<b.id : a.c-'a'<b.c-'a';
}
bool cmp2(Node a,Node b)
{
return a.id<b.id;
}
int n,k;
char s1[maxn];
int main()
{
scanf("%d%d",&n,&k);
scanf("%s",s1);
int len=strlen(s1);
for(int i=0;i<len;i++)
{
node[i].c=s1[i];
node[i].id=i;
node[i].temp=0;
}
sort(node,node+len,cmp1);
for(int i=0;i<k;i++) node[i].temp=1;
sort(node,node+len,cmp2);
for(int i=0;i<len;i++)
{
if(node[i].temp==1) continue;
else printf("%c",node[i].c);
}
printf("\n");
return 0;
}
CoderForces999C-Alphabetic Removals的更多相关文章
- code forces 999C Alphabetic Removals
C. Alphabetic Removals time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- CF999C Alphabetic Removals 思维 第六道 水题
Alphabetic Removals time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CodeForces - 999C Alphabetic Removals
C - Alphabetic Removals ≤k≤n≤4⋅105) - the length of the string and the number of letters Polycarp wi ...
- C - Alphabetic Removals
题目链接: You are given a string ss consisting of nn lowercase Latin letters. Polycarp wants to remove e ...
- Alphabetic Removals(模拟水题)
You are given a string ss consisting of nn lowercase Latin letters. Polycarp wants to remove exactly ...
- CF999C Alphabetic Removals 题解
Content 给定一个长度为 \(n\) 的仅含小写字母的字符串,执行 \(k\) 次如下操作: 如果字符串中有 a 这个字母,删除从左往右第一个 a,并结束操作,否则继续操作: 如果字符串中有 b ...
- Codeforces Round #490 (Div. 3)
感觉现在\(div3\)的题目也不错啊? 或许是我变辣鸡了吧....... 代码戳这里 A. Mishka and Contes 从两边去掉所有\(≤k\)的数,统计剩余个数即可 B. Reversi ...
- [Codeforces]Codeforces Round #490 (Div. 3)
Mishka and Contest #pragma comment(linker, "/STACK:102400000,102400000") #ifndef ONLINE_JU ...
- [codeforces] 暑期训练之打卡题(三)
每个标题都做了题目原网址的超链接 Day21<Alphabetic Removals> 题意: 给定一个字符串,要求按照字典序按照出现的前后顺序删除 k 个字母 题解: 记录字符串中各个字 ...
随机推荐
- Python 基础之socket编程(三)
python 基础之socket编程(三) 前面实现的基于socket通信只能实现什么呢?在tcp协议的通信中就是一个用户说一句,服务端给你回一句,你再给服务端说一句,服务端再给你回一句,就这样一直友 ...
- Jenkins初体验-安装与部署服务
一.概述 1.简介 在工作中接触到CD/CI,Devops相关的技术,本文记录Jenkins的基本使用.Jenkins是一款开源的持续集成工具,能够集成一套自动化部署任务. 目标 通过jenkins从 ...
- SpringBoot 源码解析 (七)----- Spring Boot的核心能力 - 自定义Servlet、Filter、Listener是如何注册到Tomcat容器中的?(SpringBoot实现SpringMvc的原理)
上一篇我们讲了SpringBoot中Tomcat的启动过程,本篇我们接着讲在SpringBoot中如何向Tomcat中添加Servlet.Filter.Listener 自定义Servlet.Filt ...
- ubuntu server 1604 配置网络信息
对于新安装的linux 服务器(ubuntu server 1604) 一,配置网络 连接网线与路由器 查看系统的网卡信息 ifconfig -a //列出所有的网卡信息,不管启用还是没有启用的 ...
- 阅读《Windows 黑客编程技术详解》(甘迪文著)【正在进行】
内容提要: 本书介绍的是黑客编程的基础技术,涉及用户层下的Windows编程和内核层下的Rootkit编程. 全书大纲: 第一篇 用户篇 平常计算机上使用的应用程序,都运行在用户层上,属于用户程序.在 ...
- 将Swagger2文档导出为HTML或markdown等格式离线阅读
网上有很多<使用swagger2构建API文档>的文章,该文档是一个在线文档,需要使用HTTP访问.但是在我们日常使用swagger接口文档的时候,有的时候需要接口文档离线访问,如将文档导 ...
- leetcode 114二叉树转换成链表
解法一 可以发现展开的顺序其实就是二叉树的先序遍历.算法和 94 题中序遍历的 Morris 算法有些神似,我们需要两步完成这道题. 将左子树插入到右子树的地方 将原来的右子树接到左子树的最右边节点 ...
- urllib练习
# coding = utf-8 """ 解析https://www.kuaidaili.com/free/网站里的代理地址, 并测试是否可用 ""& ...
- Python3学习-基础
1.直接运行.py文件 在Windows上是不行的,但是在Mac和Linux上是可以的,方法是在.py文件的第一行加上一个特殊的注释: #!/usr/bin/env python3 print('he ...
- Python爬虫之Selenium的常用方法
1.单个元素的选取 find_element_by_id 通过标签属性Id查找元素 find_element_by_name 通过标签属性name查找元素 find_element ...