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.

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.

正解:贪心

解题报告:

  最优的次数显然,方案的话,每次暴力找到一个多余的,并把多出来的部分给别的缺少的即可。

 //It is made by jump~
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int inf = (<<);
const int MAXN = ;
int n,m,ans,zong;
int a[MAXN],cnt[MAXN];
bool pd[MAXN]; inline int getint()
{
int w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar(); if(c=='-') q=,c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar(); return q ? -w : w;
} inline void work(){
n=getint(); m=getint(); for(int i=;i<=n;i++) a[i]=getint();
for(int i=;i<=n;i++) if(a[i]<=m) cnt[a[i]]++;
ans=n/m; printf("%d ",ans); bool flag=false;
for(int i=;i<=n;i++) {
if(a[i]<=m && cnt[a[i]]>ans) {
flag=false;
for(int j=;j<=m;j++) {
if(cnt[j]<ans) {
flag=true;
cnt[j]++; cnt[a[i]]--;a[i]=j; break;
}
}
if(flag) zong++;
}
else if(a[i]>m) {
flag=false;
for(int j=;j<=m;j++) {
if(cnt[j]<ans) {
flag=true;
cnt[j]++; a[i]=j;
break;
}
}
if(flag) zong++;
}
}
printf("%d\n",zong);
for(int i=;i<=n;i++) printf("%d ",a[i]);
} int main()
{
work();
return ;
}

codeforces 723C : Polycarp at the Radio的更多相关文章

  1. Codeforces 723C. Polycarp at the Radio 模拟

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

  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. cf723c Polycarp at the Radio

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

  9. codeforces 727F. Polycarp's problems

    题目链接:http://codeforces.com/contest/727/problem/F 题目大意:有n个问题,每个问题有一个价值ai,一开始的心情值为q,每当读到一个问题时,心情值将会加上该 ...

随机推荐

  1. Java 集合系列07之 Stack详细介绍(源码解析)和使用示例

    概要 学完Vector了之后,接下来我们开始学习Stack.Stack很简单,它继承于Vector.学习方式还是和之前一样,先对Stack有个整体认识,然后再学习它的源码:最后再通过实例来学会使用它. ...

  2. mssql 2008 复制订阅

    广域网的复制订阅 准备工作: 1.a.b服务器创建相同的系统用户密码 2.在a服务器 sql server 配置管理器 创建别名 ip填写b服务器的ip, b服务器端口号 3.在b服务器  sql s ...

  3. Linux shell特性

    一:别名 .alias 查看本用户下的alias配置 --自定义别名:alias 别名='shell命令' (注意是单引号) --cat $HOME/.bashrc 在这个用户下配置着alias名的配 ...

  4. Hadoop:pig 安装及入门示例

    pig是hadoop的一个子项目,用于简化MapReduce的开发工作,可以用更人性化的脚本方式分析数据. 一.安装 a) 下载 从官网http://pig.apache.org下载最新版本(目前是0 ...

  5. 编写更少量的代码:使用apache commons工具类库

    Commons-configuration   Commons-FileUpload   Commons DbUtils   Commons BeanUtils  Commons CLI  Commo ...

  6. LeetCode:Minimum Depth of Binary Tree,Maximum Depth of Binary Tree

    LeetCode:Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth ...

  7. Windjs应用

    一个异步的js类库,应用价值不大,所以代码也没在维护了.在做h5特效或者游戏动画方面有点用处. $await是Windjs的核心api.具体可以check 浅谈Jscex的$await语义及异步任务模 ...

  8. 为 Xamarin.Forms 做个跑马灯控件

    前段时间,私下用 Xamarin.Forms 做了个商业项目的演示版.很多被国内App玩坏了的控件/效果,XF上都没有或是找不到对应的实现,没有办法只能亲自上阵写了几个,效果还行,就是有BUG. 这个 ...

  9. 记、基于react-router的单页应用

    现在用react写单页应用基本上都是用react-router做前端路由了吧!最近在使用react-router的过程中遇到了不少问题,在这里总结一下. 浏览器url react-router默认提供 ...

  10. Xen

    Xen是一个开放源代码虚拟机监视器,由剑桥大学开发.它打算在单个计算机上运行多达128个有完全功能的操作系统. 在旧(无虚拟硬件)的处理器上执行Xen,操作系统必须进行显式地修改(“移植”)以在Xen ...