cf723c Polycarp at the Radio

Posted ACforever

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cf723c Polycarp at the Radio相关的知识,希望对你有一定的参考价值。

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 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



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.

/*
给一个数列,代表每每首歌谁负责唱,要让前m个歌手中演唱曲数最少的最多,求一个最少修改次数
贪心即可,so water
*/
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = 3005;
int n,m,b[maxn],a[maxn],cge[maxn][maxn],cge_a[maxn];
int ans1,ans2;
int cnt = 1,t;
int main(){
    cin>>n>>m;
    for(int i = 1;i <= n;i++){
        cin>>a[i];
        if(a[i] <= m) b[a[i]]++;
    }
    ans1 = n / m;
    for(int i = 1;i <= n;i++){
        while(b[cnt] >= ans1) cnt++;
        if(cnt > m) break;
        if(a[i] > m){
            a[i] = cnt;
            b[cnt]++;
            ans2++;
        }
    }
    for(int i = 1;i <= m;i++){
        while(b[i] > ans1){
            while(b[cnt] >= ans1) cnt++;
            if(cnt > m) break;
            b[i]--;
            cge_a[i]++;
            cge[i][cge_a[i]] = cnt;
            b[cnt]++;
            ans2++;
        }
        if(cnt > m) break;
    }
    cout<<ans1<<" "<<ans2<<endl;
    for(int i = 1;i <= n;i++){
        if(a[i] <= m)if(cge_a[a[i]]){
            t = a[i];
            a[i] = cge[t][cge_a[t]];
            cge_a[t]--;
        }
        cout<<a[i]<<" ";
    }
    return 0;
}

 

以上是关于cf723c Polycarp at the Radio的主要内容,如果未能解决你的问题,请参考以下文章

CodeForces 723C Polycarp at the Radio (题意题+暴力)

codeforces723----C. Polycarp at the Radio

CF1005D Polycarp and Div 3 思维

$CF1141C Polycarp Restores Permutation$

CF961E Tufurama

E - Complete the Projects (easy version)