click below for solution

Saturday, 29 January 2022

Subarray permutations solution|Codesheff lunchtime 2022 for div 3

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.

Solution:

This question solution is updated within contest time. please click on follow button and subscribe our channel.if you follow and subscribe our channel then get notification of answer as soon as possible.


No comments:

Post a Comment