Codeforces Round 1040 (Div. 2)
B
Pathless
Codeforces
1100
原题
← A→
翻译中…

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:

翻译中…
  • $i_1 = 1$, $i_m = n$.
  • $1 \leq i_j \leq n$ for all $1 \le j \le m$.
  • $|i_{j} - i_{j+1}| = 1$ for all $1 \leq j \lt m$.
  • $a_{i_1} + a_{i_2} + \ldots + a_{i_m} = s$.
翻译中…

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$.

翻译中…

Input

翻译中…

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$.

翻译中…

Output

翻译中…

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.

翻译中…

Note

翻译中…

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.

翻译中…

样例

Input #1
6
3 2
0 1 2
3 3
0 1 2
3 6
0 1 2
3 4
0 1 2
3 10
0 1 2
5 1000
2 0 1 1 2
Output #1
0 1 2
-1
-1
0 2 1
-1
-1
InputCopy OutputCopy
题目信息
题号
2130B
时间限制
1 s
内存限制
256 MB
标签
构造

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。