codeforces723CPolycarp at the Radio+模拟

来源:互联网 发布:生物统计 知乎 编辑:程序博客网 时间:2024/05/18 20:07

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.
有一个数组,我要用1-m这些数去替换某些数字。使得1-m中主梁最小的那个数字最大。。
首先1-m中每个数>=n/m就好了。。直接一个一个枚举,,替换就好了。。。

#include<cstdio>#include<cmath>#include<cstring>#include<iostream>#include<algorithm>#include<cstdlib>#include<queue>#include<vector>#include<map>#include<stack>#include<set>#define pi acos(-1.0)#define EPS 1e-6    //log(x)#define e exp(1.0); //2.718281828#define mod 1000000007#define INF 0x7fffffff#define inf 0x3f3f3f3ftypedef long long LL;using namespace std;int temp[2002];int x[2002];int n,m;queue<int>wei;int main(){    cin>>n>>m;    memset(temp,0,sizeof(temp));    for(int i=1;i<=n;i++){        cin>>x[i];        if(x[i]<=m) temp[x[i]]++;        else wei.push(i);    }    int step=0;    for(int i=1;i<=m;i++){        if(temp[i]<n/m){            if(wei.empty()==false) {                x[wei.front()]=i;                wei.pop();                temp[i]++;            }            else{               for(int j=1;j<=m;j++){                   if(temp[j]>n/m){                       //x[j]=i;                       for(int k=1;k<=n;k++){                         if(x[k]==j){                            x[k]=i;                            break;                         }                       }                       temp[i]++;                       temp[j]--;                       break;                   }               }            }            i--;            step++;        }        //cout<<i<<endl;    }    int out=inf;    for(int i=1;i<=m;i++){        out=min(out,temp[i]);    }    cout<<out<<" "<<step<<endl;    for(int i=1;i<=n;i++){        if(i==1) cout<<x[i];        else cout<<" "<<x[i];    }    cout<<endl;    return 0;}
0 0
原创粉丝点击