Codeforces Round #375 (Div. 2) C (贪心)

来源:互联网 发布:网络ssid没有wlan 编辑:程序博客网 时间:2024/05/18 11:02



C. Polycarp at the Radio
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented as a sequence a1, a2, ..., an, where ai is a band, which performs 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 way that the minimum among the numbers b1, b2, ..., bm will 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 playlist Polycarp needs to make to achieve it. One change in the playlist is a replacement of the performer of the i-th song with any other group.

Input

The first line of the input contains two 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 two 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 Polycarp needs to make.

In the second line print the changed playlist.

If there are multiple answers, print any of them.

Examples
input
4 21 2 3 2
output
2 11 2 1 2 



input
7 31 3 2 2 2 2 1
output
2 11 3 3 2 2 2 1 



input
4 41000000000 100 7 1000000000
output
1 41 2 3 4 



Note

In the first sample, after Polycarp's changes the first band performs two songs (b1 = 2), and the second band also performs two 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 two songs (b1 = 2), the second band performs three songs (b2 = 3), and the third band also performs two songs (b3 = 2). Thus, the best minimum value is 2.


这题有些开心的,当时比赛的时候没做出来,现在补题很快就做出来了,而且写得比学长们都简单比q巨也简单点。。嘿嘿,开心,说明我成长了~难道做了上面那个模拟的原因?

题意
有一个歌单,歌单上面有n首歌,你喜欢1,2,3....m号乐队唱的歌。

你希望改变这个歌单,使得你喜欢的乐队们唱歌唱得最少的尽量大。

问你最少修改多少次,且输出方案

注意并非歌单上所有的歌都需要修改成1-m乐队唱的,只要满足使得你喜欢的乐队们唱歌唱得最少的尽量大即可。


思路:最少的那个最多,就是k = n/m,几次操作就是1-m中一共比k小的次数和,把所有比k小的都放进队列,也就是这个值要多输出一次
#include <iostream>#include <cstdio>#include <queue>#include <cstring>using namespace std;const int maxn = 2e3 + 5;int a[maxn], book[maxn], n, m;int main(){    while(~scanf("%d%d", &n, &m))    {        memset(book, 0, sizeof(book));        for(int i = 1; i <= n; i++)            scanf("%d", &a[i]);        for(int i = 1; i <= n; i++)        {            if(a[i] <= m)                book[a[i]]++;        }        queue<int> q;        int k = n / m;        for(int i = 1; i <= m; i++)        {            if(book[i] < k)            {                for(int j = book[i]+1; j <= k; j++)                    q.push(i);            }        }        printf("%d %d\n",k, q.size());        for(int i = 1; i <= n; i++)        {            if(q.size() && (a[i] <= m && book[a[i]] > k || a[i] > m)) //这里如果所有的应该输出的都输出了,就不要再进行了            {                if(a[i] <= m) book[a[i]]--;                printf("%d%c",q.front(), i == n ? '\n' : ' ');                q.pop();            }            else                printf("%d%c", a[i], i == n ? '\n' : ' ');        }       // for(int i = 1; i <= m; i++) printf("%d\n", book[i]);    }    return 0;}


1 0