time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

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

【题解】



首先那个最小值的最大值肯定是n/m;

因为平均分才能使得最小的最大。

设k = n/m;

然后就是要维护出现次数的最小值大于等于k了;

具体的办法是把那些原序列出现次数大于k且数字本身小于等于m的数和那些数字本身大于m的数字加入到一个giver队列中。

表示这些数字都能转换成出现次数小于k的那些数字。以此来维护(1..m)权值范围内的数字出现次数的最小值大于等于k;

具体的操作看代码

#include <cstdio>
#include <queue> using namespace std; const int MAXN = 2999; struct data1
{
int what;
int num;
int idx;
}; int n, m, a[MAXN], step = 0;
int dic[MAXN];
queue <data1> q, g;
bool emp[MAXN] = { 0 }; int main()
{
//freopen("F:\\rush.txt", "r", stdin);
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
if (a[i] <= m)
dic[a[i]]++;
}
int k1;
k1 = n / m;
for (int i = 1; i <= m; i++)
if (dic[i] < k1)
{
data1 temp;
temp.what = i;
temp.num = dic[i];
q.push(temp);
}
for (int i = 1; i <= n; i++)
if (a[i] <= m)
{
if (dic[a[i]] > k1)
{
data1 temp;
temp.what = a[i];
temp.num = 1;
temp.idx = i;
g.push(temp);
}
}
else
{
data1 temp;
temp.what = a[i];
temp.num = 1;
temp.idx = i;
g.push(temp);
}
while (!q.empty())
{
data1 temp = q.front();
data1 giver = g.front();
if (giver.what <= m && emp[giver.what])//如果giver已经从大于k变成了k则emp[giver]会变成true,表示不能再用它转换了。
{
g.pop();
continue;
}
a[giver.idx] = temp.what;
step++;
if (giver.what <= m)
{
dic[giver.what]--;
if (dic[giver.what] == k1)//从大于k变成等于k则不能在用这个giver了
emp[giver.what] = true;
}
g.pop();
temp.num++;
if (temp.num == k1)
q.pop();
else
q.front().num = temp.num;
}
printf("%d %d\n", k1, step);
for (int i = 1; i <= n - 1; i++)
printf("%d ", a[i]);
printf("%d\n", a[n]);
return 0;
}

【23.48%】【codeforces 723C】Polycarp at the Radio的更多相关文章

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

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

  2. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  3. 【23. 合并K个排序链表】【困难】【优先队列/堆排序】

    合并 k 个排序链表,返回合并后的排序链表.请分析和描述算法的复杂度. 示例: 输入: [ 1->4->5, 1->3->4, 2->6] 输出: 1->1-> ...

  4. 【20.23%】【codeforces 740A】Alyona and copybooks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【23.33%】【codeforces 557B】Pasha and Tea

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【23.39%】【codeforces 558C】Amr and Chemistry

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【30.23%】【codeforces 552C】Vanya and Scales

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【16.23%】【codeforces 586C】Gennady the Dentist

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【23.26%】【codeforces 747D】Winter Is Coming

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. NYOJ_75 日期计算 (推断这一天是这一年中的第几天)

    题目地址 如题,输入一个日期,格式如:2010 10 24 ,推断这一天是这一年中的第几天. 分析:   官方给的最优答案用了for 和switch语句结合,十分巧妙. 代码 /* 如题,输入一个日期 ...

  2. 「微信小程序」有哪些冲击与机会?

    昨天晚上相信大家的朋友圈被「微信小程序」刷屏了,这影响力赶上了国务院出台新政策一样,足以说明微信在中国的影响力之大. 然后今天公号后台一大堆人问我怎么看这件事,不少人非常忧虑,仿佛自己将要失业一样. ...

  3. 小胖说事29-----iOS中Navigation中左滑pop页面的三种方法

    第三中类型.自己定义任何位置返回页面的方式,上边的类就是.m,大家能够贴过去使用.这个类是继承NavigationController的.用这个类初始化rootController就能够了.这里还有源 ...

  4. jquery init 关系

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/st ...

  5. Logstash之Logstash inputs(file和redis插件)、Logstash outputs(elasticsearch 和redis插件)和Filter plugins

     前期博客 Logstash安装和设置(图文详解)(多节点的ELK集群安装在一个节点就好) Filebeat啊,根据input来监控数据,根据output来使用数据!!! 请移步, Filebeat之 ...

  6. Codeforces 718C. Sasha and Array(线段树)

    传送门 解题思路: 这道题给了我们一个崭新的角度来看线段树. 我们常常使用的线段树是维护区间的函数的. 这里呢,提示我们线段树其实还可以维护递推. 美好的矩阵递推性质支持了这一功能. 或者说,对于递推 ...

  7. 设计模式六大原则(三):依赖倒置原则(Dependence Inversion Principle)

    依赖倒置原则(DIP)定义: 高层模块不应该依赖低层模块,二者都应该依赖其抽象:抽象不应该依赖细节:细节应该依赖抽象. 问题由来: 类A直接依赖类B,假如要将类A改为依赖类C,则必须通过修改类A的代码 ...

  8. Leetcode:populating_next_right_pointers_in_each_node题解

    一.     题目 对于结构体:struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } ...

  9. JS学习笔记 - fgm练习 2-12- 全选反选 判断CheckBox是否选中 &&运算符

    练习地址:http://www.fgm.cc/learn/lesson2/12.html 总结: 1.  && 运算符,从左向右依次执行,如果遇到 false,就不再继续执行后面的语句 ...

  10. 【2017中国大学生程序设计竞赛 - 网络选拔赛 && hdu 6154】CaoHaha's staff

    [链接]点击打开链接 [题意] 给你一个面积,让你求围成这个面积最少需要几条边,其中边的连线只能是在坐标轴上边长为1的的线或者是两个边长为1 的线的对角线. [题解] 找规律题 考虑s[i]表示i条边 ...