luogu#P16357. [BalticOI 2026] Blocks

    ID: 16536 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>Special Judge构造BalticOI(波罗的海)2026

[BalticOI 2026] Blocks

Problem Description

You have nn wooden blocks of kk different colors arranged in a line. The colors of the blocks are c1,c2,,cnc_1, c_2, \dots, c_n, all between 11 and kk.

A color is balanced if the average position of blocks with that color is (n+1)/2(n+1)/2. Note that this number is not necessarily an integer.

:::align{center} :::

For example, if 77 blocks are arranged in the above way, the average position of color 11 is (1+4+6)/3=11/3(1 + 4 + 6) / 3 = 11/3, the average position of color 22 is (2+3+7)/3=4(2 + 3 + 7) / 3 = 4 and the average position of color 33 is 55. Since (7+1)/2=4(7+1)/2=4, color 22 is balanced but colors 11 and 33 are not.

Can you order the blocks in such a way that all colors are balanced?

Input Format

The first line contains a single integer tt: the number of test cases.

The following lines describe the test cases, each consisting of two lines as follows:

The first line contains two integers nn and kk: the number of blocks and the number of different colors.

The second line contains the colors of the blocks c1,c2,,cnc_1, c_2, \dots, c_n. There is at least one block of each color.

Output Format

For each test case, print "YES" if a solution exists, and "NO" otherwise. If a solution exists, describe one possible order by printing nn integers on another line: the color of the block in each position.

3
7 2
1 1 1 1 2 2 2
2 2
1 2
2 1
1 1
YES
1 2 2 1 1 1 2
NO
YES
1 1

Hint

Explanation

In the output of the first test case, color 11 is balanced because its average position is (1+4+5+6)/4=4(1 + 4 + 5 + 6) / 4 = 4, which equals (n+1)/2(n + 1) / 2. Similarly, the average position of color 22 is (2+3+7)/3=4(2 + 3 + 7) / 3 = 4. Both colors are therefore balanced.

In the second test case, neither of the two possible orders make the colors balanced.

In the output of the third test case, blocks with color 11 appear at positions 11 and 22. The average is 3/23/2, so color 11 is balanced.

Constraints

  • 1t1001 \le t \le 100
  • 1kn21051 \le k \le n \le 2 \cdot 10^5
  • 1c1,c2,,cnk1 \le c_1, c_2, \dots, c_n \le k
  • The sum of all nn is at most 21052 \cdot 10^5

Scoring

Subtask Constraints Points
1 n3n \le 3 44
2 n15n \le 15 1313
3 There is at most one color that appears an odd number of times 1818
4 All colors appear an equal number of times 2323
5 k15k \le 15 1515
6 No additional constraints 2727