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 ;
}
最新文章
- 一行代码,让你的应用中UIScrollView的滑动与侧滑返回并存
- ant学习
- android之电话拨号器
- Jmeter上传文件
- Chorme dev tools小技巧
- 机器学习 —— 概率图模型(Homework: CRF Learning)
- 进入GRUB改root用户密码
- HTTP层 —— 中间件
- iOS网络层架构设计分享
- 【7】用Laravel5.1开发一个简单的博客系统
- 变形课hd1181(DFS)
- Bootstrap学习 - 全局CSS样式
- 解决xtrabackup command not found no mysqld group 问题
- Python学习笔记之基本语法学习1
- 利用Spring的ApplicationEvent执行自定义方法
- Bzoj1901 Dynamic Ranking
- 金山WPS一面
- 010 Editor v8.0.1(32 - bit) 算法逆向分析、注册机编写
- hive -e执行出现「cannot recognize input near &#39;<;EOF>;&#39; in select clause」问题
- Matlab:椭圆方程的导数边值问题