| Codeforces Round 1040 (Div. 2) |
|---|
| Finished |
There is an array $$$a_1, a_2, \ldots, a_n$$$ consisting of values $$$0$$$, $$$1$$$, and $$$2$$$, and an integer $$$s$$$. It is guaranteed that $$$a_1, a_2, \ldots, a_n$$$ contains at least one $$$0$$$, one $$$1$$$, and one $$$2$$$.
Alice wants to start from index $$$1$$$ and perform steps of length $$$1$$$ to the right or to the left, and reach index $$$n$$$ at the end. While Alice moves, she calculates the sum of the values she is visiting, and she wants the sum to be exactly $$$s$$$.
Formally, Alice wants to find a sequence $$$[i_1, i_2, \ldots, i_m]$$$ of indices, such that:
However, Bob wants to rearrange $$$a_1, a_2, \ldots, a_n$$$ to prevent Alice from achieving her target. Determine whether it is possible to rearrange $$$a_1, a_2, \ldots, a_n$$$ such that Alice cannot find her target sequence (even if Alice is smart enough). If it is possible, you also need to output the rearranged array $$$a_1, a_2, \ldots, a_n$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$s$$$ ($$$3 \le n \le 50$$$, $$$0 \le s \le 1000$$$).
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 2$$$).
It is guaranteed that $$$a$$$ contains at least one $$$0$$$, one $$$1$$$, and one $$$2$$$.
For each test case, if it is possible to rearrange $$$a$$$ such that Alice cannot find her target sequence, output $$$n$$$ integers — such rearrangement of $$$a$$$. Otherwise, output $$$-1$$$ instead.
63 20 1 23 30 1 23 60 1 23 40 1 23 100 1 25 10002 0 1 1 2
0 1 2 -1 -1 0 2 1 -1 -1
In the first test case, any rearrangement of $$$a$$$ can prevent Alice from achieving her target.
In the second test case, regardless of rearranging $$$a$$$, Alice can always find the sequence $$$[1,2,3]$$$ as her target sequence.
In the third test case,there is no rearrangement of $$$a$$$ that can prevent Alice from achieving her target. For example, for $$$a=[0,2,1]$$$, Alice can find the sequence $$$[1,2,3,2,3]$$$ as her target sequence.
| Name |
|---|


