You are given an array a consisting of n integer numbers.
You have to color this array in k colors in such a way that:
Each element of the array should be colored in some color;
For each i from 1 to k there should be at least one element colored in the i-th color in the array;
For each i from 1 to k all elements colored in the i-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,…cn, where 1≤ci≤k and ci is the color of the i-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 n and k (1≤k≤n≤5000) — the length of the array a and the number of colors, respectively.
The second line of the input contains n integers a1,a2,…,an (1≤ai≤5000) — elements of the array a.
Output
If there is no answer, print “NO”. Otherwise print “YES” and any coloring (i.e. numbers c1,c2,…cn, where 1≤ci≤k and ci is the color of the i-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
Input
5 2
2 1 1 2 1
Output
NO
Note
In the first example the answer 2 1 2 1 is also acceptable.
In the second example the answer 1 1 1 2 2 is also acceptable.
There exist other acceptable answers for both examples.
思路:先把所有的k种颜色都涂抹上去,再来判断那些相同的已经被涂抹,在这里我用的是二维数组visit[i][arr[i]] 第i种颜色涂抹在了arr[i]位置上
我错误原因是没有把k种颜色利用完,只想着相同数字填不同颜色,visit[j+1][arr[i]] = 1;填完之后没有做标记
代码:
#include<iostream>
using namespace std;
int arr[6000];
int sum[6000];
int b[6000];
int visit[6000][6000];
int main()
{
int n,k;
cin >> n >> k;
for(int i = 0; i < n; i++)
{
cin >> arr[i];
sum[arr[i]]++;
}
for(int i = 0; i < n; i++)
{
if(sum[arr[i]]>k)
{
cout << "NO";
return 0;
}
}
if(n < k)
{
cout << "NO";
return 0;
}
for(int i = 0; i < n; i ++)
{
if(i < k)
{
b[i] = i+1;
visit[i+1][arr[i]] = 1;
}
else
{
for(int j = 0; j < k; j++)
{
if(visit[j+1][arr[i]] == 0)
{
b[i] = j+1;
visit[j+1][arr[i]] = 1;
break;
}
}
}
}
cout << "YES" << endl;
for(int i = 0; i < n; i++)
{
cout << b[i] << " ";
}
cout << endl;
return 0;
}