300617: CF118C. Fancy Number
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Fancy Number
题意翻译
给出车牌号码n个数,改变其中的一些数使得有相同的k个数,改变一次所付出的代价为两个数的差的绝对值,求最少的代价并输出字典序最小的一个。 感谢@Oscar12345 提供的翻译题目描述
A car number in Berland consists of exactly $ n $ digits. A number is called beautiful if it has at least $ k $ equal digits. Vasya wants to change the digits in his car's number so that the number became beautiful. To replace one of $ n $ digits Vasya has to pay the sum of money, equal to the absolute difference between the old digit and the new one. Help Vasya: find the minimum sum of money he should pay to make the number of his car beautiful. You should also find the resulting beautiful number. If there are several such numbers, then print the lexicographically minimum one.输入输出格式
输入格式
The first line contains two space-separated integers $ n $ and $ k $ ( $ 2<=n<=10^{4},2<=k<=n $ ) which represent how many digits the number has and how many equal digits a beautiful number should have. The second line consists of $ n $ digits. It describes the old number of Vasya's car. It is guaranteed that the number contains no spaces and only contains digits.
输出格式
On the first line print the minimum sum of money Vasya needs to change the number. On the second line print the car's new number. If there are several solutions, print the lexicographically minimum one.
输入输出样例
输入样例 #1
6 5
898196
输出样例 #1
4
888188
输入样例 #2
3 2
533
输出样例 #2
0
533
输入样例 #3
10 6
0001112223
输出样例 #3
3
0000002223