CF2145D Inversion Value of a Permutation
Description
A permutation of length $ n $ is an array of $ n $ integers, where each number from $ 1 $ to $ n $ appears exactly once. An inversion in a permutation $ p $ is a pair of indices $ (i, j) $ such that $ i < j $ and $ p_i > p_j $ .
For a permutation $ p $ , we define its inversion value as the number of its subsegments that contain at least one inversion. Formally, this is the number of pairs of integers $ (l, r) $ ( $ 1 \le l < r \le n $ ) for which there exists a pair of indices $ (i, j) $ satisfying the following conditions: $ l \le i < j \le r $ and $ p_i > p_j $ .
For example, for the permutation $ [3, 1, 4, 2] $ , the inversion value is $ 5 $ .
You are given two integers $ n $ and $ k $ . Your task is to construct a permutation of length $ n $ with an inversion value equal to exactly $ k $ .
Input Format
The first line contains one integer $ t $ ( $ 1 \le t \le 500 $ ) — the number of test cases.
Each test case consists of a single line containing two integers $ n $ and $ k $ ( $ 2 \le n \le 30 $ ; $ 0 \le k \le \dfrac{n(n-1)}{2} $ ).
Output Format
For each test case, output the answer as follows:
- if the desired permutation does not exist, output a single integer $ 0 $ ;
- otherwise, output $ n $ distinct integers from $ 1 $ to $ n $ — the desired permutation. If there are multiple such permutations, you may output any of them.