#P10311. 「Cfz Round 2」Weighted Mean
「Cfz Round 2」Weighted Mean
Problem Description
Given a sequence of length and an integer , it is guaranteed that every element in is a positive integer not greater than , and all elements are pairwise distinct.
You need to construct a sequence of length such that:
- Every element in is a positive integer not greater than .
- $\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 is , the weighted mean of sequence is an integer.
- There does not exist an ordered triple of integers such that and .
Or report that there is no solution.
Input Format
This problem contains multiple test cases.
The first line contains an integer , which denotes the number of test cases.
Then each test case is given as follows:
- The first line contains two integers .
- The second line contains integers, representing the given sequence .
Output Format
For each test case, output one line:
- If there exists a sequence that satisfies the conditions, output integers separated by spaces, representing the sequence you constructed.
- If no such sequence exists, output .
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 st 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 .
However, output 1 6 1 is incorrect. Although its weighted mean is , it has .
Output 1 2 3 is also incorrect, because its weighted mean is , which is not an integer.
Output 1 1 1 is also incorrect. Although its weighted mean is , there exists an ordered triple such that and .
For the nd test case, it can be proven that no sequence satisfying the conditions exists.
For the rd 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 denote the sum of within a single test file.
For all testdata, , , , . It is guaranteed that all elements in sequence are pairwise distinct.
You can get the score for this problem only if you pass all test points.
Translated by ChatGPT 5