43 lines
899 B
C++
43 lines
899 B
C++
#include <bits/stdc++.h>
|
||
using namespace std;
|
||
int n, k;
|
||
const int N = 10010;
|
||
int a[N];
|
||
int x;
|
||
int res = 0x3f3f3f3f;
|
||
/*
|
||
6 5
|
||
898196
|
||
*/
|
||
|
||
struct Node {
|
||
int idx;
|
||
int num;
|
||
} b[N];
|
||
|
||
bool cmp(int p, int q) {
|
||
return abs(p - x) < abs(q - x);
|
||
}
|
||
int main() {
|
||
cin >> n >> k; // n个长度,k个相同的数字
|
||
string s;
|
||
cin >> s;
|
||
for (int i = 0; i < n; i++) a[i] = s[i] - '0';
|
||
|
||
// for (int i = 0; i < n; i++) cout << a[i] << " ";
|
||
|
||
for (x = 0; x <= 9; x++) { // 枚举最终是哪个数字占了k位
|
||
int cost = 0;
|
||
for (int i = 0; i < n; i++) b[i] = a[i];
|
||
sort(b, b + n, cmp);
|
||
for (int i = 0; i < n; i++)
|
||
cout << b[i] << " ";
|
||
|
||
cout << endl;
|
||
// for (int i = 0; i < k; i++) cost += abs(b[i] - x);
|
||
|
||
// res = min(res, cost);
|
||
}
|
||
cout << res << endl;
|
||
return 0;
|
||
} |