Description
Polycarp is a music editor at the radio station. He received a playlist for tomorrow, which can be represented as a sequence A1, A2, ..., an, where Ai is a band, which perf Orms the i-th song. Polycarp likes bands with the numbers from 1 to M, but he doesn ' t really like others.
We define as BJ the number of songs the group J is going to perform tomorrow. Polycarp wants to change the playlist in such a is the minimum among the numbers B1, B2, ..., BM would be as large as Possible.
Find this maximum possible value of the minimum among the BJ (1≤J≤M), and the minimum number of changes in the Playlis T Polycarp needs to achieve it. One change in the playlist are a replacement of the performer of the I-th song with any other group.
Input
The first line of the input contains the integers n and M (1≤m≤n≤2000).
The second line contains n integers a1, a2, ..., an (1≤ai≤109), where AI is the performer of the I-th song.
Output
In the first line print integers:the maximum possible value of the minimum among the BJ (1≤J≤M), where BJ is the Number of songs in the changed playlist performed by the j-th band, and the minimum number of changes in the playlist Poly Carp needs to make.
The second line print the changed playlist.
If There is multiple answers, print any of them.
Sample Input Input
4 2
1 2 3 2
Output
2 1
1 2 1 2
Input
7 3
1 3 2 2 2 2 1
Output
2 1
1 3 3 2 2 2 1
Input
4 4
1000000000 100 7 1000000000
Output
1 4
1 2 3 4
Hint
In the first sample, after Polycarp ' s changes the first band performs, songs (B1 = 2), and the second band also perform S-Songs (b2 = 2). Thus, the minimum of these values equals to 2. It is impossible to achieve a higher minimum value by any changes in the playlist.
In the second sample, after Polycarp ' s changes the first band performs the songs (B1 = 2), the second band performs three Songs (b2 = 3), and the third band also performs, songs (b3 = 2). Thus, the best minimum value is 2
This is completely a reading comprehension question, test instructions has been engaged for half a day to understand Otz
For the sake of convenience, we first define how many times each number appears in the array, which is called the number of times.
Test instructions: Give two numbers n and M, and then give n numbers in the array a[i]. Make the number in array a all the number between 1~m, and the frequency of each number as large as possible, that is, the frequency of each number is higher than the average. The output array then changes the minimum value in all number of frequencies and changes the array several times, as well as the changed array.
You can know that the mean is n/m, and then in the array A to find the number of 1~m and record the number of times, if above the average to find the next, below the average note that the number of the difference can reach the average, so that the number of changes can be calculated. Finally in the array to find all the non-conforming number of "frequency too small need to be large frequency to this number, greater than m need to become smaller" to get rid of.
#include <cstdio> #include <cstring> int a[2000 + 5], val[2000 + 5];
BOOL pos[2000 + 5];
int main () {int n, m;
int Min_ave, min_cnt;
Memset (POS, False, sizeof (POS));
scanf ("%d%d", &n, &m);
for (int i = 1; I <= n; ++i) scanf ("%d", &a[i]);
Min_ave = n/m;
min_cnt = 0;
for (int i = 1; I <= m; ++i) {int num = 0;
for (int j = 1; j <= N; ++j) {if (a[j] = = i) {Pos[j] = true;
num++;
} if (num >= min_ave) break;
} if (num < Min_ave) {val[i] = Min_ave-num;
Min_cnt + = Val[i];
}} int cur = 1;
for (int i = 1, i <= m; ++i) {for (int j = 0, J < val[i]; ++j) {while (Pos[cur])
cur++;
a[cur++] = i;
}} printf ("%d%d\n", Min_ave, min_cnt); for (int i = 1; I <= n; ++i) {printf ("%d", a[i]);
if (i < n) printf ("");
} printf ("\ n");
return 0;
}