ques description
input & output
logic and implementation of the ques
A permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, (1), (4,3,5,1,2), (3,2,1) are permutations, and (1,1),(4,3,1), (2,3,4) are not.
For a permutation p of length n, lets define its score as the sum of |i−j| for all the pairs (ai,aj) where aj−ai=1 (1≤ai≤n−1).
In other words, the score of the permutation is equal to dist(1,2)+dist(2,3)+…. +dist(n−1,n) where dist(a,b) means the distance between a and b in the permutation p.
Example :
For the permutation (1,3,4,2)
dist(1,2)=|1−4|=3
dist(2,3)=|4−2|=2
dist(3,4)=|2−3|=1
So, the score of the permutation s=3+2+1=6.
Given two integers n and k. You need to construct a permutation of length n with its score equal to k or state that it is impossible to do so. If there are multiple valid permutations, print any of them.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains two integer n and k (2≤n≤2×105, 1≤k≤109) —the length of the permutation and the needed score of the permutation.
The sum of n over all test cases does not exceed 2×105.
Output
For each test case, print a permutation of length n with its score equal to k. If multiple valid permutations exist, print any of them. If no such permutation exists, print −1.
sample input and output
input
3
4 5
6 12
5 3
output
1 4 2 3
2 6 5 1 4 3
-1
hello873 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5