You have an arrangement a with n components 1,2,3,… ,k−1,k,k−1,k−2,… ,k−(n−k) (k≤n<2k). How about we call as reversal in a couple of files ia[j]. Assume, you have some change p of size k and you assemble an arrangement b of size n in the accompanying way: b[i]=p[a[i]].
Correct answer will be upvoted else downvoted. Computer science.
You have an arrangement a with n components 1,2,3,… ,k−1,k,k−1,k−2,… ,k−(n−k) (k≤n<2k).
How about we call as reversal in a couple of files i<j to such an extent that a[i]>a[j].
Assume, you have some change p of size k and you assemble an arrangement b of size n in the accompanying way: b[i]=p[a[i]].
You will probably find such change p that the absolute number of reversals in b doesn't surpass the all out number of reversals in a, and b is lexicographically greatest.
Little update: the grouping of k integers is known as a stage in the event that it contains all integers from 1 to k precisely once.
Another little update: a grouping s is lexicographically more modest than another succession t, if either s is a prefix of t, or for the primary I to such an extent that si≠ti, si<ti holds (in the principal position that these arrangements are unique, s has more modest number than t).
Input
The principal line contains a solitary integer t (1≤t≤1000) — the number of experiments.
The solitary line of each experiment contains two integers n and k (k≤n<2k; 1≤k≤105) — the length of the arrangement an and its most extreme.
It's dependable that the all out amount of k over experiments doesn't surpass 105.
Output
For each experiment, print k integers — the stage p which augments b lexicographically without expanding the complete number of reversals.
It tends to be demonstrated that p exists and is novel.
Step by step
Solved in 4 steps with 1 images