cf-723C Polycarp at the Radio

题目点击打开链接  http://codeforces.com/contest/723/problem/C

分析:先定义每个数字在数组中出现次数叫做这个数的频率,注意是次数。

题意:给出两个数字 n 和 m,再给出 n 个数字放在数组 a[i] 里。使数组 a 里面的数全部变为 1~m 之间的数字,并且使每个数的频率尽量大,也就是每个数的频率高于平均值。然后输出数组改变后所有数频率中的最小值 和 改变数组时改变了几次,以及改变后的数组。

可以知道平均值就是 n/m,然后在数组a中找到符合 1~m 的数字并记录下次数,如果高于平均值就再找下一个,低于平均值则记下差几个数能够到达平均值,这样可以求出改变次数。最后在数组中找到所有不符合条件的数【频率太小需要将频率大的改为这个数,大于m的需要变小】改掉

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.

Example

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.

#include<iostream>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2050;
int a[N],val[N],p[N];
int pos[2005];
int main(){int n,m,min_ave,min_cnt;memset(pos,0,sizeof(pos));cin>>n>>m;for(int i=1;i<=n;i++){cin>>a[i];}min_ave=n/m;min_cnt=0;for(int i=1;i<=m;i++){int num=0;for(int j=1;j<=n;j++){if(a[j]==i){pos[j]=1;num++;}if(num>=min_ave){break;}}if(num<min_ave){val[i]=min_ave-num;min_cnt+=val[i];}}int count=1;for(int i=1;i<=m;i++){for(int j=0;j<val[i];j++){while(pos[count]==1){count++;}a[count++]=i;}}cout<<min_ave<<" "<<min_cnt<<endl;for(int i=1;i<=n;i++){cout<<a[i]<<" ";}cout<<endl;return 0;
} 

cf-723C Polycarp at the Radio相关推荐

  1. cf723c Polycarp at the Radio

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

  2. linux touch命令对于windows,Windows代替touch命令

    codeforces 723C : Polycarp at the Radio Description Polycarp is a music editor at the radio station. ...

  3. 【Codeforces】Round #375 (Div. 2)

    Position:http://codeforces.com/contest/723 我的情况 啊哈哈,这次raiting肯定要涨,接受过上次的教训,先用小号送肉,大号都是一发切,重回蓝咯 结果... ...

  4. 2016区域赛前冲刺训练

    UPD 2016.10.23 shift-and (2题) Codeforces 训练 现在已经完成了: 191 [Codeforces Round #377] (6/6) Div 2 A Buy a ...

  5. 第一次打CF的感受(附A-C题题解) -Codeforces Round #764 (Div. 3)

    目录 A题-在子集上加一 B题-制作AP C题- 除以2和排列 个人感受 A题-在子集上加一 题目 Polycarp得到了一个整数数组a[1-n]作为礼物.现在,他希望执行一定数量的操作(可能为零), ...

  6. CF杂题训练(交互题不做,2500以上的看情况吧)

    CF专练 CF1562 A The Miracle and the Sleeper B Scenes From a Memory C Rings D Two Hundred Twenty One E ...

  7. 【解题报告】CF DIV3 #ROUND 734 A~D1

    [解题报告]CF DIV2 #ROUND 707 A~D 比赛链接 比赛评价: 一般性,有段时间没打了,甚至忘记多组输入hh.顺便吐槽一下翻译软件确实不行,以后还是直接看英文好了 A. Polycar ...

  8. 【CF套题】 Educational Codeforces Round 58

    [前言] 组队CF之帮wyl上橙,我和sc打小号上紫. 结果sc成功FST两题,wyl成功skipped. 我的小号幸存了qwq. [题目] 原题地址 A.Minimum Integer 特判一下dd ...

  9. 2019.4.30 WAGV CF Team replay

    前言 4月30号的2小时CF重现赛,基本都是DIV2的水题,目标是训练CF题目的题感来上分,主要是读英文题有困难,对题意理解困难- 比赛地址:https://cn.vjudge.net/contest ...

最新文章

  1. SharpDevelop
  2. Spark快速上手-WordCount案例
  3. storm从入门到放弃(一),storm介绍
  4. Hadoop和Spark生态圈了解
  5. linux resin 服务功能,linux服务之resin
  6. 匈牙利命名法为何被淘汰_被称为手表中“蓝血贵族”的百达翡丽,为何会受到如此的追捧?...
  7. oracle数据库如何写翻页_ORACLE翻页SQL语句
  8. 对当今流行的比赛评分系统的简单分类以及《评委计分系统-双屏版》的类别
  9. matlab 离散积分器设置,MATLABSIULINK积分器相关操作.docx
  10. 软件系统开发费用的估算——功能点方法
  11. 图片如何转PDF格式?这些方法值得收藏
  12. 《遗传算法原理及应用》笔记—并行遗传算法
  13. USBCAN上位机软件的使用
  14. 非直角平面坐标系下的坐标换算
  15. 微信公众号推送的模板消息无法跳转到小程序指定页面?
  16. 手持式频谱分析仪怎么选择
  17. Meson构建系统(二)
  18. JRuby: Wiki: RailsWithH2InJNDIOnJetty — Project Kenai
  19. R语言(pROC)绘图
  20. .NET 6 Minimal API 的经验分享

热门文章

  1. 怎样学好Java语言
  2. [pytest源码3]-pluggy代码结构与核心设计
  3. 【DaVinci Developer专题】-14-Array IDT几类特殊形式“二维数组”总结(Implementation Data Type)
  4. python3*1**3 表达式输出结果为_下列 Python语句的输出结果是?
  5. Windows Server 2012 配置语言 系统语言中文(汉化)
  6. DS树--二叉树之最大路径
  7. pm4py、graphviz绘图中文乱码问题
  8. 服务器 搭建虚拟主机,server2016下搭建web服务器三种虚拟主机实验文档
  9. web漏洞之越权漏洞
  10. kafka的基本知识(面试备用)