Subarray permutations

 A permutation of length 

N is an array of N integers P=[P1,P2,,PN] such that every integer from 1 to N (inclusive) appears in it exactly once. For example, [2,3,4,1] is a permutation of length 4.

A subsegment of an array A[LR]=[AL,AL+1,,AR] is called good if the subsegment is a permutation of length (RL+1). For example, the array A=[2,3,1,4,2] contains 3 good subsegments: A[33]=[1], A[13] =[2,3,1], A[25]=[3,1,4,2].

You are given two integers N and K. Find a permutation of length N such that it contains exactly K good subsegments. Print -1 if no such permutation exists.

Input Format

  • The first line contains an integer T, denoting the number of test cases. The T test cases then follow:
  • The first and only line of each test case contains two space-separated integers N,K.

Output Format

For each test case, output a single line containing the answer:

  • If no permutation satisfies the given conditions, print −1.
  • Otherwise, print N space-separated integers P1,P2,,PN, denoting the elements of the permutation. If there are multiple answers, you can output any of them.

Constraints

  • 1T103
  • 1N105
  • 1KN
  • Sum of N over all test cases does not exceed 3105.

Subtasks

  • Subtask 1 (100 points): Original constraints

Sample Input 1 

4
1 1
3 2
4 1
5 3

Sample Output 1 

1
1 3 2 
-1
5 3 1 4 2

Explanation

Test case 1: The only permutation of length 1 is [1], which contains one good subsegment A[11].

Test case 2: The permutation [1,3,2] contains 2 good subsegments: A[11]A[13].

Test case 3: There is no way to construct a permutation of length 4 which contains one good subsegment.

Test case 4: The permutation [5,3,1,4,2] contains 3 good subsegments: A[33],A[25],A[15]. There are other permutations of length 5 having 3 good subsegments

Comments

Popular posts from this blog

Walmart Sparkplug 2022 | 150 students will be selected for summer internship | ₹1-1.1 lakh monthly

Flipkart Runway: Season 3 | 2025 | Internship

Python for Data Science NPTEL Assignment Solutions Week 4 2022

GATE 2022 Answer Key Release Date Announced; Details Here