codeforces723CPolycarp at the Radio+模拟
来源:互联网 发布:生物统计 知乎 编辑:程序博客网 时间:2024/05/18 20:07
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.
有一个数组,我要用1-m这些数去替换某些数字。使得1-m中主梁最小的那个数字最大。。
首先1-m中每个数>=n/m就好了。。直接一个一个枚举,,替换就好了。。。
#include<cstdio>#include<cmath>#include<cstring>#include<iostream>#include<algorithm>#include<cstdlib>#include<queue>#include<vector>#include<map>#include<stack>#include<set>#define pi acos(-1.0)#define EPS 1e-6 //log(x)#define e exp(1.0); //2.718281828#define mod 1000000007#define INF 0x7fffffff#define inf 0x3f3f3f3ftypedef long long LL;using namespace std;int temp[2002];int x[2002];int n,m;queue<int>wei;int main(){ cin>>n>>m; memset(temp,0,sizeof(temp)); for(int i=1;i<=n;i++){ cin>>x[i]; if(x[i]<=m) temp[x[i]]++; else wei.push(i); } int step=0; for(int i=1;i<=m;i++){ if(temp[i]<n/m){ if(wei.empty()==false) { x[wei.front()]=i; wei.pop(); temp[i]++; } else{ for(int j=1;j<=m;j++){ if(temp[j]>n/m){ //x[j]=i; for(int k=1;k<=n;k++){ if(x[k]==j){ x[k]=i; break; } } temp[i]++; temp[j]--; break; } } } i--; step++; } //cout<<i<<endl; } int out=inf; for(int i=1;i<=m;i++){ out=min(out,temp[i]); } cout<<out<<" "<<step<<endl; for(int i=1;i<=n;i++){ if(i==1) cout<<x[i]; else cout<<" "<<x[i]; } cout<<endl; return 0;}
- codeforces723CPolycarp at the Radio+模拟
- Codeforces723 C. Polycarp at the Radio (模拟)
- codeforces 723C. Polycarp at the Radio [模拟]【杂类】
- C. Polycarp at the Radio
- [codeforces723C]Polycarp at the Radio
- CF_C. Polycarp at the Radio
- codeforces Polycarp at the Radio
- CodeForces 723C-Polycarp at the Radio(模拟 贪心 vector乱搞)
- codefroces 723c Polycarp at the Radio
- codeforces723C- Polycarp at the Radio-greedy
- Codeforces 723 C. Polycarp at the Radio
- Codeforces 723C.Polycarp at the Radio
- Codeforce 723C - Polycarp at the Radio
- CodeForces723C Polycarp at the Radio 贪心
- HDU4072Working at the Restaurant(模拟)
- [codeforces] C. Polycarp at the Radio 数组统计
- 【23.48%】【codeforces 723C】Polycarp at the Radio
- Codeforces Round #375 (Div. 2)-C. Polycarp at the Radio
- Codeforces 723E.One-Way Reform
- 求一个十进制正整数在二进制表示中的二进制数字个数
- noip2012借教室
- 【神经网络与深度学习】【C/C++】ZLIB学习2
- 求素数最优代码(python)
- codeforces723CPolycarp at the Radio+模拟
- 目标 : webview使用
- 15 关于netbeans7.0.1, c,c++的安装
- Codeforces723 C. Polycarp at the Radio (模拟)
- redis--事务处理与乐观锁
- [LeetCode-Java]31. Next Permutation
- 栈结构的四则运算
- 数据搜索的相关资料
- [Android测试] AS+Appium+Java+Win 自动化测试之八:使用PageObject模式和重封装