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

题目连接:http://codeforces.com/contest/723/problem/C


题意:改变播放清单里面的尽量少的播放歌曲,使得1~m播放次数最小的尽可能大。

思路:播放清单里面,1~m里面每首歌至少有播放n/m遍。

代码:

#include<bits/stdc++.h>
using namespace std;
int a[];
int sign[],flag[];
int main()
{
int i,j,n,m;
scanf("%d%d",&n,&m);
for(i=; i<=n; i++)
{
scanf("%d",&a[i]);
if(a[i]<=m) sign[a[i]]++;
}
int cou=n/m,amount=n%m;
int ans=;
for(i=; i<=n; i++)
{
if(a[i]<=m&&sign[a[i]]<cou+) continue;
if(a[i]<=m&&sign[a[i]]==cou&&amount>=)
{
if(flag[a[i]]==) amount--;
flag[a[i]]=;
continue;
}
for(j=; j<=m; j++)
if(sign[j]<cou)
{
if(a[i]<=m) sign[a[i]]--;
sign[j]++;
a[i]=j;
ans++;
break;
}
}
cout<<cou<<" "<<ans<<endl;
for(i=; i<=n; i++)
cout<<a[i]<<" ";
cout<<endl;
return ;
}

Codeforces 723C. Polycarp at the Radio 模拟的更多相关文章

  1. codeforces 723C : Polycarp at the Radio

    Description Polycarp is a music editor at the radio station. He received a playlist for tomorrow, th ...

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

    题意:给定 n 个数,让把某一些变成 1-m之间的数,要改变最少,使得1-m中每个数中出现次数最少的尽量大. 析:这个题差不多读了一个小时吧,实在看不懂什么意思,其实并不难,直接暴力就好,n m不大. ...

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

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

  4. Codeforces 659F Polycarp and Hay 并查集

    链接 Codeforces 659F Polycarp and Hay 题意 一个矩阵,减小一些数字的大小使得构成一个连通块的和恰好等于k,要求连通块中至少保持一个不变 思路 将数值从小到大排序,按顺 ...

  5. 【23.48%】【codeforces 723C】Polycarp at the Radio

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【Codeforces 723C】Polycarp at the Radio 贪心

    n个数,用最少的次数来改变数字,使得1到m出现的次数的最小值最大.输出最小值和改变次数以及改变后的数组. 最小值最大一定是n/m,然后把可以改变的位置上的数变为需要的数. http://codefor ...

  7. Codeforces Round #375 (Div. 2) Polycarp at the Radio 优先队列模拟题 + 贪心

    http://codeforces.com/contest/723/problem/C 题目是给出一个序列 a[i]表示第i个歌曲是第a[i]个人演唱,现在选出前m个人,记b[j]表示第j个人演唱歌曲 ...

  8. Codeforces Round #528-A. Right-Left Cipher(字符串模拟)

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  9. cf723c Polycarp at the Radio

    Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be re ...

随机推荐

  1. 10、java中的抽象类

    当多个类中出现相同功能,但是功能主体不同,这是可以进行向上抽取.这时,只抽取功能定义,而不抽取功能主体. 抽象:看不懂. 抽象类的特点:1,抽象方法一定在抽象类中.2,抽象方法和抽象类都必须被abst ...

  2. 动态布局--动态修改RelativeLayout宽高的方法

    本文实例讲述了Android编程动态修改RelativeLayout宽高的方法.分享给大家供大家参考,具体如下: 我们经常会动态修改RelativeLayout的宽高,这样的代码,比较简单,就是修改R ...

  3. Windows下PHP版本选取

    1. 下载地址 http://windows.php.net/download/ 2. PHP大版本 PHP4:由于太古老.对OO支持不力已基本被淘汰. PHP5:分为三个分支——PHP5.2之前的版 ...

  4. 阿里 classloader

    http://blog.csdn.net/scythe666/article/details/51956047

  5. Zerojudge解题心得

    我进入娄山中学已经有1年多了,也就是说我学习编程也有1年多了,在这一年多的时间中,我已经对编程有了初步的了解.其实只要抓住平时的空闲时间加以利用,哪怕每个星期就做那么三四题,经过了一段时间沉淀,也会有 ...

  6. nginx+tomcat+memcached-session-manager组成简单的负载均衡和集群

    1.搭建环境 192.168.29.128(luxh-01.com) 安装nginx,参考 http://www.cnblogs.com/luxh/p/4067038.html 192.168.29. ...

  7. ubuntu14.04网络设置

    修改ip: /etc/network/interfaces

  8. Data Science at the Command Line学习笔记(一)

    学习Data Science at the Command Line时,win7下安装环境是遇到了一些小问题,最后通过百度解决. 官方指导可以在这个地址找到:http://datascienceatt ...

  9. python字典访问的三种方法

    定义字典 dic = {'a':"hello",'b':"how"} 法一: for key in dic: print key,dic[key] # a he ...

  10. javascript立即执行函数 (function(){})()

    看到一段代码: (function(){ var outer = $('#subject'); outer.find('li').on('mouseover', mouseover); })() ( ...