| TheForces Round #31 (Div2.9-Forces) |
|---|
| Finished |
Pritesh had a permutation $$$p$$$ of length $$$n$$$. He took all the prefixes $$$[p_1, p_2, \dots, p_i]$$$ ($$$1\leq i\leq n$$$) of the permutation $$$p$$$ and calculated the $$$\operatorname{MEX}$$$ (minimal excluded element) of each prefix. Unfortunately, he forgot the permutation but remembers the sum $$$S$$$ of all the MEX values. Can you help him find the permutation $$$p$$$?
If there are multiple solutions, print any of them. If there is no solution, print a single integer $$$-1$$$.
The $$$\operatorname{MEX}$$$ of a collection of integers $$$c_1, c_2, \ldots, c_k$$$ is defined as the smallest non-negative integer $$$x$$$ which does not occur in the collection $$$c$$$.
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$0$$$ to $$$n-1$$$ in arbitrary order. For example, $$$[2, 3, 1, 0, 4]$$$ is a permutation, but $$$[0, 1, 1]$$$ is not a permutation ($$$1$$$ appears twice in the array), and $$$[0, 2, 3]$$$ is also not a permutation ($$$n = 3$$$ but there is $$$3$$$ in the array).
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$S$$$ ($$$1 \le n \le 3 \times 10^5$$$, $$$1 \le S \le 10^9$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \times 10^5$$$.
For each test case, output the permutation $$$p$$$ of length $$$n$$$ such that the sum of the MEX of all prefixes equals $$$S$$$. If there are multiple solutions, print any of them. If there is no solution, print a single integer $$$-1$$$.
43 52 102 24 3
0 2 1 -1 1 0 -1
For the first test case, $$$\operatorname{MEX}([0]) + \operatorname{MEX}([0, 2]) + \operatorname{MEX}([0, 2, 1]) = 1 + 1 + 3 = 5$$$.
For the second test case, it can be shown that no such permutation exists.
| Name |
|---|


