Problem D

Statement
Copy Copied
D. Inversion Value of a Permutationtime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputA 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$$$.InputThe 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}$$$).OutputFor 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. ExampleInput54 55 105 06 83 1Output3 1 4 2
5 4 3 2 1
1 2 3 4 5
2 3 5 6 1 4
0

Evaluations

Eval IDRun IDProviderModelLangSuccessTimestampPromptResponseStdoutStderrRetry
97 20260126-054408 vertex gemini-3-pro-preview go true 2026-01-26T06:14:07.060254Z View View View View Retry