Generating A Permutation

All submissions for this problem are available.
For a permutation P = (p_{1}, p_{2}, ..., p_{N}) of numbers [1, 2, ..., N], we define the function f(P) = max(p_{1}, p_{2}) + max(p_{2}, p_{3}) + ... + max(p_{N1}, p_{N}).
You are given N and an integer K. Find and report a permutation P of [1, 2, ..., N] such that f(P) = K, if such a permutation exists.
Note f([1]) = 0.
Input
 The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
 The only line of each test case consists of two spaceseparated integers N, K respectively.
Output
For each test case, if a permutation satisfying the condition exists, output a single line containing N spaceseparated integers which denotes any such permutation. If no such permutation exists, output a single integer 1 instead.
Use fast I/O methods since the size of the output is large.
Constraints
 1 ≤ T ≤ 40
 1 ≤ N ≤ 10^{5}
 Sum of N over all test cases in each file ≤ 10^{6}
 0 ≤ K ≤ 2 * 10^{10}
Example
Input: 3 4 12 2 2 5 14 Output: 1 1 2 5 4 3 2 1
Explanation
Example 1. There doesn't exist any permutation of numbers [1, 2, 3, 4] that can have its f value equal to 4. Hence answer is 1.
Example 2. The permutations [1, 2] and [2, 1] both have their f values equal to 2. You can print any of these two permutations.
Example 3. The permutation [5, 4, 3, 2, 1] has f value = max(5, 4) + max(4, 3) + max(3, 2) + max(2, 1) = 5 + 4 + 3 + 2 = 14.
Author:  architk 
Editorial  https://discuss.codechef.com/problems/GENPERM 
Tags  acm17kgp, architk, constructive, easymedium, kgp17rol 
Date Added:  13122017 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 