Codeforces Round #375 (Div. 2) C

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 21 2 3 2

output

2 11 2 1 2 

input

7 31 3 2 2 2 2 1

output

2 11 3 3 2 2 2 1 

input

4 41000000000 100 7 1000000000

output

1 41 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首歌曲,ai 表示唱歌的乐队,题目主角喜欢1 2 ..M的乐队,希望歌单全是他们唱的,并且要求唱歌最少的乐队唱的歌的数目也是最小值中最大的(举个列子,5可以分为1 4,2 3,2是最小中的最大值)

解法:当然是平分啦,ans=n/m,那么我们遍历1到M,如果bi乐队(乐队小于M)唱的歌小于ans,从a数组不符合要求的元素(比如ai乐队唱的歌大于ans或者ai乐队大于M)中拿,处理一下拿走的元素就行

#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;

int a[100000];
map<int,int>q;
int num=0;
int main()
{
    int n,m;
    int ans;
    cin>>n>>m;
    ans=n/m;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        q[a[i]]++;
    }
    num=0;
    for(int i=1;i<=m;i++)
    {
        if(q[i]<ans)
        {
            while(q[i]<ans)
            {
                for(int j=0;j<n;j++)
                {
                   // cout<<i<<"A"<<endl;
                    if(a[j]>m||q[a[j]]>ans)
                    {
                      //  cout<<i<<" "<<a[j]<<endl;
                        q[a[j]]--;
                        q[i]++;
                        a[j]=i;
                        num++;
                        break;
                    }
                }
            }
        }
    }
    cout<<ans<<" "<<num<<endl;
    for(int i=0;i<n;i++)
    {
        cout<<a[i]<<" ";
    }
    return 0;
}

  


时间: 2024-10-12 12:13:13

Codeforces Round #375 (Div. 2) C的相关文章

Codeforces Round #375 (Div. 2) D. Lakes in Berland DFS

D. Lakes in Berland 链接: http://codeforces.com/problemset/problem/723/D 题意 给你一个n/*m的矩阵,然后你们有不少于k条湖泊,然后你需要使得一些湖泊变成陆地,使得湖泊的数量恰好等于k,问你至少填多少个水. 湖泊不与外界相邻. 题解: 直接dfs搜出每一条湖泊,然后放在优先队列里,从小到大去填满就好了. 代码: 1 #include<iostream> 2 #include<queue> 3 #include&l

Codeforces Round #375 (Div. 2) A

Description There are three friend living on the straight line Ox in Lineland. The first friend lives at the point x1, the second friend lives at the point x2, and the third friend lives at the point x3. They plan to celebrate the New Year together,

Codeforces Round #375 (Div. 2)

这是我打的第一场现场CF,才涨了4分= =,太菜啦.. 第一题,超级大水题,不说了.. 第二题,也挺水的,要注意的是,最后一个字符如果不是下划线或者括号结束的话,仍然要判断那个单词.因为这点WA了好多次. 第三题,rejudge的时候错了= =..题目意思有点晦涩,其实还是比较水的题,题目要求前m个组合唱的歌的数目的最小值要最大,那么这个最大值很显然是n/m,向下取整,然后从1遍历到n,如果数字大于m的或者小于等于m但是其出现的次数过多的(大于n/m)都把它变成不足n/m次的数字,然后我当时因为

Codeforces Round #375 (Div. 2) B

Description Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters. In this problem you should implement the similar functionality. You

Codeforces Round #375 (Div. 2)E. One-Way Reform

题目链接:传送门 题目大意:一副无向图,要求你给边定向(变为有向图),使出度等于入度的点最多,输出有多少 个点,并且输出定向后的边(前为起点,后为终点) 题目思路:欧拉路 我们这样考虑,先考虑无向图的点的度数,如果为奇数则一定无法变为题目要求的点,ans-1 对于度为偶数的点则一定可以通过调整满足. 处理方法:新建一个虚拟节点0,使所有度为奇数的点向其连一条边,那么最终图中的点的度数都为偶数. 这样就满足欧拉路的条件了.我们只需要跑欧拉路并且将走过的路径保留下来即可. 注意将与虚拟节点连的边删去

Codeforces Round #375 (Div. 2) ABCDE

A - The New Year: Meeting Friends 水 #include<iostream> #include<algorithm> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; cout<<max(a,max(b,c)) - min(a,min(b,c)) <<endl; return 0; } B - Text Document A

Codeforces Round #375 (Div. 2) A B C D F

A 数轴上有三个人要到一个点去过年 使三个人走路距离的和最小  让两边的人都走到中间那个点即可 B 给出一个字符串 其中有_ ( ) 三种字符和英文字母 连续的英文字母是一个单词 括号对中不会套括号对 求 括号外最长的单词长度 括号内有多少单词 维护一个bool变量表示当前单词在不在括号内 res表示当前单词的长度 可见 _() 都是分隔符 C 给出一个节目表 其中有n个曲目 每一个ai 代表这个曲目由ai乐队演奏 但是某人只喜欢标号是1-m的乐队 现在他可以对每个节目的乐队进行更换 问 最少更

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i