#P16456. [UOI 2026] Intersection of Prefix Sums

    ID: 16442 Type: RemoteJudge 300ms 512MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>Special Judge2026UOI(乌克兰)

[UOI 2026] Intersection of Prefix Sums

题目描述

You are given an array aa of nn integers and an integer xx.

You need to rearrange the elements of the array so that in the resulting array there is no non-empty\textbf{non-empty} prefix with sum equal to xx, or report that this is impossible.

In other words, you need to find a permutation p1,p2,,pnp_1, p_2, \dots, p_n of the elements of array aa such that for every kk (1kn)(1 \le k \le n) the following holds: p1+p2++pkx.p_1 + p_2 + \dots + p_k \neq x.

输入格式

The first line contains one integer tt (1t104)(1 \le t \le 10^4)~--- the number of test cases.

Each test case consists of two lines.

The first line of each test case contains two integers nn, xx (1n105,x1015)(1 \le n \le 10^5, |x| \le 10^{15}) --- the number of elements in the array and the forbidden prefix sum.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (ai109)(|a_i| \le 10^9) --- the elements of the array.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

输出格式

For each test case, output the answer in the following format.

In the first line, output YES\texttt{YES} if there exists a permutation of array aa with no non-empty prefix whose sum is xx. Otherwise, output NO\texttt{NO}.

If the answer is YES\texttt{YES}, then in the second line output nn integers separated by spaces --- the required permutation of array aa.

If there are multiple correct permutations, you may output any of them.

The strings YES\texttt{YES} and NO\texttt{NO} may be printed in any case. For example, yes\texttt{yes}, Yes\texttt{Yes}, and YES\texttt{YES} will all be considered the same.

For each block, you can receive half of the points\textbf{half of the points} 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 YES\texttt{YES} or NO\texttt{NO} for each test case of the corresponding subtask.

Note that if you output YES\texttt{YES}, then the next line must contain exactly nn integers separated by spaces. To obtain full points\textbf{full points}, these nn integers must form a permutation of array aa that does not contain a non-empty prefix with sum xx.

To obtain half\textbf{half} of the points, these nn integers may be arbitrary. They may even not be elements of array aa.

If after YES\texttt{YES} you do not output exactly nn integers, then you cannot get even half of the points for that test case.

For example, suppose that for some test case n=5n = 5 and the correct answer is YES\texttt{YES}. Then for half of the points you may output:

YES
1 1 1 1 1

even if array aa does not contain such numbers.

But you cannot output only:

YES

In that case, after YES\texttt{YES}, a line with exactly nn integers in the range [109;109][-10^9; 10^9] 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 [2,1,2,1,3,2][2, 1, 2, 1, -3, 2]. The prefix sums of this sequence are [2,3,5,6,3,5][2, 3, 5, 6, 3, 5] and do not contain the number 44. There are also other permutations that work.

In the second example, there is only one permutation, and its prefix sums contain the number 77.

Scoring

  • (22 points): ai=a1a_i = a_1 for all ii;
  • (44 points): x=0x = 0;
  • (44 points): t=1t = 1, n9n \le 9;
  • (66 points): t=1t = 1, n15n \le 15;
  • (88 points): ai>0a_i > 0 for all ii, x200x \le 200;
  • (1414 points): the array contains at most two distinct values;
  • (1010 points): if a correct permutation exists, it can be obtained by swapping the first element of the array with some other element;
  • (1212 points): ai>0a_i > 0 for all ii;
  • (1616 points): the array contains exactly one negative number;
  • (2424 points): no additional constraints.