Codeforces Round #531 (Div. 3)

Posted kaike

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #531 (Div. 3)相关的知识,希望对你有一定的参考价值。

Codeforces Round #531 (Div. 3)

B. Array K-Coloring

Description

You are given an array aa consisting of nn integer numbers.

You have to color this array in kk colors in such a way that:

  • Each element of the array should be colored in some color;
  • For each ii from 11 to kk there should be at least one element colored in the ii-th color in the array;
  • For each ii from 11 to kk all elements colored in the ii-th color should be distinct.

Obviously, such coloring might be impossible. In this case, print "NO". Otherwise print "YES" and any coloring (i.e. numbers c1,c2,cnc1,c2,…cn, where 1cik1≤ci≤k and cici is the color of the ii-th element of the given array) satisfying the conditions above. If there are multiple answers, you can print any.

Input

The first line of the input contains two integers nn and kk (1kn50001≤k≤n≤5000) — the length of the array aa and the number of colors, respectively.

The second line of the input contains nn integers a1,a2,,ana1,a2,…,an (1ai50001≤ai≤5000) — elements of the array aa.

output

If there is no answer, print "NO". Otherwise print "YES" and any coloring (i.e. numbers c1,c2,cnc1,c2,…cn, where 1cik1≤ci≤kand cici is the color of the ii-th element of the given array) satisfying the conditions described in the problem statement. If there are multiple answers, you can print any.

Examples

Input

4 2
1 2 2 3

Output

YES
1 1 2 2

Input

5 2
3 2 1 2 3

Output

YES
2 1 1 2 1

 

正确解法:

用k的颜色填充n个数字,k个颜色要用完,每种数字的颜色不能一样。

原本知道肯定是排序,但是我只能保证有这种情况,肯定小于等于k,不能保证k一定用完。

看了题解。排序,然后第k个数是第k个颜色。第k+1的数是第1种颜色。

保证有k个颜色。

不会vector

感觉我这种数据一大就会tle。死亡。

技术分享图片
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<string>
 4 #include<cstring>
 5 #include<map>
 6 #include<set>
 7 #include<algorithm>
 8 #include<cmath>
 9 #include<cstdlib>
10 using namespace std;
11 int n, k,b[5100];
12 struct student
13 {
14     int shu, zhi,id;
15 }a[5100];
16 int cmp1(student x, student y)
17 {
18     return (x.shu < y.shu);
19 }
20 int cmp2(student x, student y)
21 {
22     return (x.id < y.id);
23 }
24 int main()
25 {
26     scanf("%d %d",&n,&k);
27     for (int i = 1; i <= n; i++)
28     {
29         scanf("%d",&a[i].shu);
30         b[a[i].shu]++;
31         a[i].id = i;
32     }
33     sort(a + 1, a + n + 1, cmp1);
34     int maxx = 0;
35     for (int i = 1; i <= 5000; i++)
36         maxx = max(b[i],maxx);
37     if (maxx > k)
38     {
39         printf("NO
");
40         return 0;
41     }
42     int kk = 0;
43     for (int i = 1; i <= n; i++)
44     {
45         a[i].zhi = kk % k + 1;
46         kk++;
47     }
48     sort(a + 1, a + n + 1, cmp2);
49     printf("YES
");
50     for (int i = 1; i <= n; i++)
51     {
52         if (i == 1)    printf("%d",a[i].zhi);
53         else printf(" %d",a[i].zhi);
54     }
55     printf("
");
56     return 0;
57 }
View Code

 





以上是关于Codeforces Round #531 (Div. 3)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #531 (Div. 3)

Codeforces Round #436 E. Fire(背包dp+输出路径)

[ACM]Codeforces Round #534 (Div. 2)

Codeforces #531.div3

Codeforces Round #726 (Div. 2) B. Bad Boy(贪心)

Codeforces Global Round 19