#P16456. [UOI 2026] Intersection of Prefix Sums
[UOI 2026] Intersection of Prefix Sums
题目描述
You are given an array of integers and an integer .
You need to rearrange the elements of the array so that in the resulting array there is no prefix with sum equal to , or report that this is impossible.
In other words, you need to find a permutation of the elements of array such that for every the following holds:
输入格式
The first line contains one integer ~--- the number of test cases.
Each test case consists of two lines.
The first line of each test case contains two integers , --- the number of elements in the array and the forbidden prefix sum.
The second line of each test case contains integers --- the elements of the array.
It is guaranteed that the sum of over all test cases does not exceed .
输出格式
For each test case, output the answer in the following format.
In the first line, output if there exists a permutation of array with no non-empty prefix whose sum is . Otherwise, output .
If the answer is , then in the second line output integers separated by spaces --- the required permutation of array .
If there are multiple correct permutations, you may output any of them.
The strings and may be printed in any case. For example, , , and will all be considered the same.
For each block, you can receive if for every test case in that block you correctly determine whether the required permutation exists. That is, to obtain half of the points, it is enough to correctly output or for each test case of the corresponding subtask.
Note that if you output , then the next line must contain exactly integers separated by spaces. To obtain , these integers must form a permutation of array that does not contain a non-empty prefix with sum .
To obtain of the points, these integers may be arbitrary. They may even not be elements of array .
If after you do not output exactly integers, then you cannot get even half of the points for that test case.
For example, suppose that for some test case and the correct answer is . Then for half of the points you may output:
YES
1 1 1 1 1
even if array does not contain such numbers.
But you cannot output only:
YES
In that case, after , a line with exactly integers in the range is not output.
2
6 4
1 1 2 2 2 -3
3 7
7 7 7
YES
2 1 2 1 -3 2
NO
提示
Note
In the first example, there exists a permutation . The prefix sums of this sequence are and do not contain the number . There are also other permutations that work.
In the second example, there is only one permutation, and its prefix sums contain the number .
Scoring
- ( points): for all ;
- ( points): ;
- ( points): , ;
- ( points): , ;
- ( points): for all , ;
- ( points): the array contains at most two distinct values;
- ( points): if a correct permutation exists, it can be obtained by swapping the first element of the array with some other element;
- ( points): for all ;
- ( points): the array contains exactly one negative number;
- ( points): no additional constraints.