#P10311. 「Cfz Round 2」Weighted Mean

    ID: 11205 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学洛谷原创Special JudgeO2优化构造洛谷月赛Ad-hoc

「Cfz Round 2」Weighted Mean

Problem Description

Given a sequence aa of length nn and an integer mm, it is guaranteed that every element in aa is a positive integer not greater than mm, and all elements are pairwise distinct.

You need to construct a sequence bb of length nn such that:

  • Every element in bb is a positive integer not greater than mm.
  • $\dfrac{\sum\limits_{i=1}^n (a_i \cdot b_i)}{\sum\limits_{i=1}^n b_i}$ is an integer. That is, when the weight of aia_i is bib_i, the weighted mean of sequence aa is an integer.
  • There does not exist an ordered triple of integers (i,j,k)(i,j,k) such that 1i<j<kn1\le i<j<k\le n and bi=bj=bkb_i=b_j=b_k.

Or report that there is no solution.

Input Format

This problem contains multiple test cases.

The first line contains an integer TT, which denotes the number of test cases.

Then each test case is given as follows:

  • The first line contains two integers n,mn,m.
  • The second line contains nn integers, representing the given sequence aa.

Output Format

For each test case, output one line:

  • If there exists a sequence bb that satisfies the conditions, output nn integers separated by spaces, representing the sequence bb you constructed.
  • If no such sequence bb exists, output 1-1.

Any output that satisfies the requirements will be accepted.

3
3 5
1 2 3
2 2
1 2
4 100000
1 2 5 9
1 2 1
-1
1 1 3 4

Hint

"Sample Explanation #1"

For the 11st test case, the weighted mean of the sample output is $\dfrac{1 \times 1+2 \times 2 + 3 \times 1}{1+2+1}=2$, which is an integer.

Output 1 5 1 is also considered correct, and its weighted mean is 22.

However, output 1 6 1 is incorrect. Although its weighted mean is 22, it has b2>5b_2>5.

Output 1 2 3 is also incorrect, because its weighted mean is 73\dfrac{7}{3}, which is not an integer.

Output 1 1 1 is also incorrect. Although its weighted mean is 22, there exists an ordered triple (1,2,3)(1,2,3) such that 11<2<331 \leq 1 < 2 < 3 \leq 3 and b1=b2=b3b_1=b_2=b_3.

For the 22nd test case, it can be proven that no sequence bb satisfying the conditions exists.

For the 33rd test case, the weighted mean of the sample output is $\dfrac{1 \times 1+2 \times 1 + 5 \times 3+9 \times 4}{1+1+3+4}=6$, which is an integer.

Constraints

Let n\sum n denote the sum of nn within a single test file.

For all testdata, 1T10001 \le T \le 1000, 1n1061 \le n \le 10^6, 1aim1091 \le a_i \le m \le 10^9, n106\sum n \le 10^6. It is guaranteed that all elements in sequence aa are pairwise distinct.

You can get the score for this problem only if you pass all test points.

Translated by ChatGPT 5