C. Alphabetic Removals
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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).

Examples
input
Copy
15 3
cccaabababaccbc
output
Copy
cccbbabaccbc
input
Copy
15 9
cccaabababaccbc
output
Copy
cccccc
input
Copy
1 1
u
output
Copy

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的更多相关文章

  1. code forces 999C Alphabetic Removals

    C. Alphabetic Removals time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  2. CF999C Alphabetic Removals 思维 第六道 水题

    Alphabetic Removals time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. CodeForces - 999C Alphabetic Removals

    C - Alphabetic Removals ≤k≤n≤4⋅105) - the length of the string and the number of letters Polycarp wi ...

  4. C - Alphabetic Removals

    题目链接: You are given a string ss consisting of nn lowercase Latin letters. Polycarp wants to remove e ...

  5. Alphabetic Removals(模拟水题)

    You are given a string ss consisting of nn lowercase Latin letters. Polycarp wants to remove exactly ...

  6. CF999C Alphabetic Removals 题解

    Content 给定一个长度为 \(n\) 的仅含小写字母的字符串,执行 \(k\) 次如下操作: 如果字符串中有 a 这个字母,删除从左往右第一个 a,并结束操作,否则继续操作: 如果字符串中有 b ...

  7. Codeforces Round #490 (Div. 3)

    感觉现在\(div3\)的题目也不错啊? 或许是我变辣鸡了吧....... 代码戳这里 A. Mishka and Contes 从两边去掉所有\(≤k\)的数,统计剩余个数即可 B. Reversi ...

  8. [Codeforces]Codeforces Round #490 (Div. 3)

    Mishka and Contest #pragma comment(linker, "/STACK:102400000,102400000") #ifndef ONLINE_JU ...

  9. [codeforces] 暑期训练之打卡题(三)

    每个标题都做了题目原网址的超链接 Day21<Alphabetic Removals> 题意: 给定一个字符串,要求按照字典序按照出现的前后顺序删除 k 个字母 题解: 记录字符串中各个字 ...

随机推荐

  1. Unity 横版2D移动跳跃问题——关于一段跳与二段跳

    1.初始条件: 1.角色只绑定一个碰撞体,移动时施加力或给予速度,用跳跃次数JumpTimes或者bool值OnGround判断是否在地面. 2.只用一个tilemap搭建2D场景,因此所有tilem ...

  2. ActiveMQ消息队列从入门到实践(1)—JMS的概念和JMS消息模型

    1. 面向消息的中间件 1.1 什么是MOM 面向消息的中间件,Message Oriented Middleware,简称MOM,中文简称消息中间件,利用高效可靠的消息传递机制进行平台无关的数据交流 ...

  3. Jenkins + docker ,容器中跑docker服务

    1. 宿主机:安装docker 2. 启动jenkins服务 https://jenkins.io/download/ Jenkins官网找自己需要的镜像版本号进行使用. docker run -it ...

  4. nyoj 45-棋盘覆盖 (高精度, Java)

    棋盘覆盖 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 在一个2k×2k(1<=k<=100)的棋盘中恰有一方格被覆盖,如图1(k=2时),现用一缺角的 ...

  5. Spring Bean的生命周期、后置处理器、定义继承

    目录: 了解Spring的基本概念 Spring简单的示例 Spring Bean的定义及作用域 1.Bean的生命周期 Bean的生命周期可以简单的理解为:Bean的定义——Bean的初始化——Be ...

  6. spark thriftserver

    spark可以作为一个分布式的查询引擎,用户通过JDBC的形式无需写任何代码,写写sql就可以实现查询啦,spark thriftserver的实现也是相当于hiveserver2的方式,并且在测试时 ...

  7. 树的点分治 (poj 1741, 1655(树形dp))

    poj 1655:http://poj.org/problem?id=1655 题意: 给无根树,  找出以一节点为根,  使节点最多的树,节点最少. 题解:一道树形dp,先dfs 标记 所有节点的子 ...

  8. Win32 COM组件 x Android Service (二)

    继续上一篇. 如果不使用AIDL(Android Interface Definition Language接口描述语言)编写服务接口的话,(COM组件,CORBA组件,ICE组件以及其它远程调用框架 ...

  9. aws msk

    1. 建立3个私网子网 2. 建立msk

  10. echarts绘制彩虹色背景

    大致成品如图所示 关键的步骤: var dom = document.getElementById("myChart"); var myChart = echarts.init(d ...