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个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- C语言文法翻译
<程序>→<外部声明>|<程序><外部声明> <外部声明>→<函数定义>|<声明> <函数定义>→< ...
- Objective - C 之类目
一.类目(category):为已有的类(可以是系统类,也可以是自定义类)添加公有的新的方法: 例如:为系统已有的NSString类添加一个比较字符串大小的方法 1.创建过程: 2.NSString ...
- Linux学习笔记3
touch filename 创建一个不存在的文件,或者修改文件的时间戳. touch log.txt whereis name 定位一个文件. whereis php.ini whereis.loc ...
- JDK1.8最新特性--Lambda表达式(重点)
一个旧版本JDK简单匿名类的用例如下所示: // Java 8之前: JButton show = new JButton("Show"); show.addActionListe ...
- CSS中可以和不可以继承的属性【转】
一.无继承性的属性 1.display:规定元素应该生成的框的类型 2.文本属性: vertical-align:垂直文本对齐 text-decoration:规定添加到文本的装饰 text-shad ...
- 开源人脸识别face_recognition
环境:python36 1.安装dlib.face_recognition windows版 下载dlib,cp后面是py版本 下载地址:https://pypi.org/simple/dlib/ 提 ...
- CentOS卸载系统自带的OpenJDK并安装Sun的JDK的方法
查看目前系统的jdk: rpm -qa | grep jdk 得到的结果: [root@dc-01 java]# rpm -qa | grep jdk java-1.6.0-openjdk-1.6. ...
- 教你配置使用阿里云 Maven 库,体验秒下 jar 包的快感
鉴于国内的网络环境,从默认 Maven 库下载 jar 包是非常的痛苦. 速度慢就不说了,还经常是下不下来,然后一运行就是各种 ClassNotFoundException,然后你得找到残留文件删掉重 ...
- HttpWebRequest 保存Cookies,模拟Session登录
前面使用HttpWebRequest 对象可以抓取网页中一些资料,不过有些页面可以直接打开,而有些页面必登录之后才能打开,也就是在登录后保存登录信息在Session,这样就可以访问有权限的页面了.下面 ...
- python的N个小功能(高斯模糊原理及实践)
原理: 二维高斯函数 1) 为了计算权重矩阵,需要设定σ的值.假定σ=1.5,则模糊半径为1的权重矩阵如下: 2) 这9个点的权重总和等于0.4787147,如果只计算 ...