Given two integers $N$ and $K$. Your task is to construct an array $A$ such that:
- $A$ is a permutation with size $N$. (i.e. All $N$ integers from $1$ to $N$ must appear exactly once in $A$)
- The number of inversions inside $A$ is exactly $K$.
A pair of elements $(A_i, A_j)$ is considered an inversion if and only if $i \lt j$ and $A_i \gt A_j$.
For example, in the array $A=[2, 4, 1, 3]$, there are three pairs of inversion: $(A_1, A_3)$, $(A_2, A_3)$ and $(A_2, A_4)$.
Please note that there might be no valid solution.
Input
The only line contains two integers $N$ and $K$.
Output
If there is no valid solution, output $-1$.
Otherwise, output $N$ integers on a single line, denoting the array $A$. If there are multiple answers, output any of them.
Subtasks
For all test cases, $2 \le N \le 2 \times 10^5$, $0 \le K \le 10^{18}$
| Subtask | Score | Additional Constraints |
|---|---|---|
| $1$ | $10$ | $K = 0$ |
| $2$ | $20$ | $N \le 10$ |
| $3$ | $30$ | $K < N$ |
| $4$ | $40$ | No Additional Constraints |
Sample Test Cases
| Input | Output | |
|---|---|---|
| 4 3 | 2 4 1 3 | |
This test cases corresponds to the example given in the statement. |
||
| 5 4 | 5 1 2 3 4 | |
The four pairs of inversions are $(A_1, A_2)$, $(A_1, A_3)$, $(A_1, A_4)$ and $(A_1, A_5)$. |
||
Scoring: Per Subtask
Authored by s22f26
Appeared in 2026 Mini Comp 6 (Constructive Algorithms & Special Tasks)