Codeforces Round #375 (Div. 2) C. Polycarp at the Radio 贪心

C. Polycarp at the Radio

题目连接:

http://codeforces.com/contest/723/problem/C

Description

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.

Sample Input

4 2
1 2 3 2

Sample Output

2 1
1 2 1 2

Hint

题意

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

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

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

题解:

显然是每个乐队演唱n/m首歌,然后我们就维护一下这个就好了。

贪心的for两次。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2005;
int n,m;
int a[maxn];
int cnt[maxn],vis[maxn];
int ans2=0;
int main()
{
    scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int ans1=n/m;
	int p=n%m;
	for(int i=1;i<=n;i++)
	{
		if(a[i]>m)continue;
		if(cnt[a[i]]>=ans1)continue;
		cnt[a[i]]++;
		vis[i]=1;
	}
	for(int i=1;i<=n;i++)
	{
		if(vis[i])continue;
		int Ans1=1e9,Ans2=1e9;
		for(int j=1;j<=m;j++)
		{
			if(cnt[j]<Ans2)
				Ans2=cnt[j],Ans1=j;
		}
		if(Ans2==ans1)continue;
		ans2++;
		cnt[Ans1]++,a[i]=Ans1;
	}
	cout<<ans1<<" "<<ans2<<endl;
	for(int i=1;i<=n;i++)
		cout<<a[i]<<" ";
	cout<<endl;
}
posted @ 2016-10-04 09:24  qscqesze  阅读(345)  评论(0编辑  收藏  举报