CodeForces - 999C
You are given a string ss consisting of nn lowercase Latin letters. Polycarp wants to remove exactly kkcharacters (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
15 3
cccaabababaccbc
cccbbabaccbc
15 9
cccaabababaccbc
cccccc
1 1
u
删字母
自认为代码写的还算优美(嘻嘻)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<iostream>
using namespace std;
char con[];
int check[];
int main()
{
int i,p,j;
int n,k;
scanf("%d%d",&n,&k);
getchar();
for(i=;i<n;i++)
{
scanf("%c",&con[i]);
check[con[i]]++;
}
con[i]=; for(i='a';i<='z'+;i++)
{
if(k<=)
break;
if(k-check[i]>=)
k-=check[i];
else
{
check[i]=k;
k=;
}
}
for(;i<='z';i++)
check[i]=; for(i=;i<n;i++)
{
if(check[con[i]]>)
{
check[con[i]]--;
}
else
printf("%c",con[i]);
}
putchar('\n'); return ;
}
CodeForces - 999C的更多相关文章
- CodeForces - 999C Alphabetic Removals
C - Alphabetic Removals ≤k≤n≤4⋅105) - the length of the string and the number of letters Polycarp wi ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- 201621123037 《Java程序设计》第9周学习总结
作业09-集合与泛型z 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 这次改一个方式,就不用思维导图了,用图文结合方式来总结 1. Map三视图 键值: S ...
- windows操作系统下载tomcat,并与eclipse进行整合
进入Tomcat官网之后,在左边我们看到,Tomcat的有6,7,8这三个最流行的版本,我们可以点击进去下载想要的版本. 进入里面之后,可以看见有64位的和32位的,就看自己的电脑是多少位的了,如果电 ...
- 【前端学习笔记03】JavaScript对象相关方法及封装
//Object.create()创建对象 var obj = Object.create({aa:1,bb:2,cc:'c'}); obj.dd = 4; console.log(obj.cc); ...
- 给定一个字符串 s,找到 s 中最长的回文子串。你可以假设 s 的最大长度为1000。
给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为1000. 示例 1: 输入: "babad" 输出: "bab" 注意: &quo ...
- 洛谷P1144 最短路计数 及其引申思考
图论题目练得比较少,发一道spfa的板子题目- 题目:P1144 题目描述 给出一个N个顶点M条边的无向无权图,顶点编号为1-N.问从顶点1开始,到其他每个点的最短路有几条. 输入输出格式 输入格式: ...
- JAVA中的堆、栈等内存分析
在 JAVA 中,有六个不同的地方可以存储数据 1. 寄存器( register ) 这是最快的存储区,因为它位于不同于其他存储区的地方——处理器内部.但是寄存器的数量极其有限,所以寄存器由编译器根据 ...
- Ckeditor与Ckfinder(java)整合实现富媒体内容编辑(支持文件上传)
先来看一下最终的效果图 一.编辑器界面 二.上传图片界面 <!-------------------------------------------------------> 一.安装包下 ...
- 【NOI2006】聪明的导游
[NOI2006]聪明的导游 题面 洛谷 题目描述 小佳最近迷上了导游这个工作,一天到晚想着带游客参观各处的景点.正好 M 市在举行 NOI,来参观的人特别的多.不少朋友给小佳介绍了需要导游的人. M ...
- Web服务器进程连接数和请求连接数
1.查看Web服务器进程连接数: netstat -antp | grep 80 | grep ESTABLISHED -c 2.查看Web服务器的并发请求数及其TCP连接状态: netstat -n ...
- 洛谷 P1410 子序列(DP)
这题的题解的贪心都是错误的...正解应该是个DP 考虑有哪些有关的条件:两个序列的当前长度, 两个序列的末尾数, 把这些都压进状态显然是会GG的 考虑两个长度加起来那一位的数一定是其中一个序列的末尾, ...