A8229 | Homework
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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<=10^{5}$ ). The string consists of lowercase Latin letters. The second line contains the number $k$ ( $0<=k<=10^{5}$ ).
输出格式
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.
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
输出 #1
1 aaaaa
输入 #2
abacaba 4
输出 #2
1 aaaa
输入 #3
abcdefgh 10
输出 #3
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.
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++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted