CodeForces 102C Homework​求助

CodeForces 102C Homework
CodeForces 102C Homework
//求助各位大佬

题目描述

Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of n small Latin letters; the task was to learn the way the letters that the string contains are written. However, as Gerald is too lazy, he has no desire whatsoever to learn those letters. That's why he decided to lose some part of the string (not necessarily a connected part). The lost part can consist of any number of segments of any length, at any distance from each other. However, Gerald knows that if he loses more than k characters, it will be very suspicious.

Find the least number of distinct characters that can remain in the string after no more than k characters are deleted. You also have to find any possible way to delete the characters.

输入描述:

			
			

The first input data line contains a string whose length is equal to n (1 ≤ n ≤ 105). The string consists of lowercase Latin letters. The second line contains the number k (0 ≤ k ≤ 105).

输出描述:

			
			

Print on the first line the only number m — the least possible number of different characters that could remain in the given string after it loses no more than k characters.

Print on the second line the string that Gerald can get after some characters are lost. The string should have exactly m distinct characters. The final string should be the subsequence of the initial string. If Gerald can get several different strings with exactly m distinct characters, print any of them.

示例1

输入


aaaaa
4
abacaba
4
abcdefgh
10

输出


1
aaaaa
1
aaaa
0

备注:

			
			

In the first sample the string consists of five identical letters but you are only allowed to delete 4 of them so that there was at least one letter left. Thus, the right answer is 1 and any string consisting of characters "a" from 1 to 5 in length.

In the second sample you are allowed to delete 4 characters. You cannot delete all the characters, because the string has length equal to 7. However, you can delete all characters apart from "a" (as they are no more than four), which will result in the "aaaa" string.

In the third sample you are given a line whose length is equal to 8, and k = 10, so that the whole line can be deleted. The correct answer is 0 and an empty string.
#C/C++#
全部评论
不就是尽量找点出现次数少的字母删光吗...
点赞 回复 分享
发布于 2019-01-08 18:21
老哥你起码把题面翻译一下啊
点赞 回复 分享
发布于 2019-01-05 15:50
点赞 回复 分享
发布于 2019-01-05 11:26

相关推荐

05-07 13:29
已编辑
门头沟学院 Java
北斗导航Compass低仿版:能不能先搞清楚优先级啊,怎么可能是项目问题,项目很重要吗?又没学历 又没实习大厂凭啥约面?那玩具项目 没应用在真实生产环境下的 就算做上天又有什么用?早点找个小公司实习 拿小公司实习去投大厂实习,这才是你现在该做的
投递美团等公司9个岗位 简历被挂麻了,求建议
点赞 评论 收藏
分享
05-20 02:34
已编辑
华中科技大学 游戏策划
ResourceUtilization:你是我见过最美丽的牛客女孩你的眼睛里面有星星
投递腾讯等公司9个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务