#CODEFORCESP6992. Homework
Homework
题目描述
Gerald在上学的一天,他的老师在班上布置了一项作业:她给每个同学一个有n个小写拉丁字母(即英文字母)的字符串,要求学生学习这个字符串中的字母的写法。但是,由于Gerald太懒了,他不想学习这些字母。这就是为什么他决定丢掉这个字符串的部分(不需要是连续的一部分)。他所丢失的部分可以由若干个任意长度在任意位置的连续的子字符串组成。但是,Gerald知道,如果他丢掉了超过k个字母,他就会显得非常可疑。
请求出在不超过k个字母被删除之后,字符串中最少剩下多少个不同的字母。你还需要求出一种删除这些字母的方式。
输入格式:
输入的第一行是一个长度为n的字符串( )。这个字符串由小写拉丁字母组成。输入的第二行是数k( )。
输出格式:
请在第一行只输出数m——从这个字符串中删除k个字符之后最少剩下的最少的不同字母的个数。
在第二行输出在删除一些字母之后Gerald所能得到的字符串。这个字符串应该刚好有m个不同的字母。这个最终的字符串应该是原字符串的一个子串。如果Gerald能够得到多个都刚好有m个不同字母的不同的字符串,输出其中任意一个。
说明
在第一个样例中这个字符串含有5个字母但是你只允许删去其中4个,所以会剩下至少一个字母。所以,正确答案就是1和任意一个长度在1到5的、只含有字母a的字符串。
在第二个杨立忠你可以删去4个字母。你不能删去所有的字母,因为这个字符串的长度是7。 但是,你可以删去所以除了a以外的字母(这样的字母不多于4个),所以得到的答案是"aaaa"。
在第三个样例中字符串的长度是8,且k=10,所以可以将所有的字母都删去。正确答案是0和空字符串。
Description
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.
Input
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).
Output
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.
Samples
aaaaa
4
1
aaaaa
abacaba
4
1
aaaa
abcdefgh
10
0
Note
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.