311267: CF1958E. Yet Another Permutation Constructive

Memory Limit:512 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Yet Another Permutation Constructivetime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

Suppose you have a permutation $p$ of $n$ integers — an array where each element is an integer from $1$ to $n$, and every integer from $1$ to $n$ appears exactly once.

In one operation, you remove every element of this permutation which is less than at least one of its neighbors. For example, when you apply the operation to $[3, 1, 2, 5, 4]$, you get $[3, 5]$. If you apply an operation again, you get $[5]$.

It's easy to see that after applying a finite number of operations, you get an array consisting of a single integer $n$.

You are given two integers $n$ and $k$. Find a permutation of $n$ integers such that it becomes an array consisting of a single element $n$ after exactly $k$ operations (and not earlier).

Input

The first line contains one integer $t$ ($1 \le t \le 2000$) — the number of test cases.

Each test case consists of one line containing two integers $n$ and $k$ ($2 \le n \le 100$; $1 \le k \le n - 1$).

Output

For each test case, print the answer as follows:

  • if a permutation of size $n$ which becomes an array consisting of a single element $n$ after exactly $k$ operations does not exist, print $-1$;
  • otherwise, print $n$ distinct integers from $1$ to $n$ — the requested permutation. If there are multiple such permutations, print any of them.
ExampleInput
4
5 2
5 4
2 1
3 2
Output
3 1 2 5 4
-1
1 2
2 1 3

Output

题目大意:
这个题目是关于排列的构造问题。给定一个整数n,其排列p是一个数组,其中的每个元素都是1到n之间的整数,且每个整数1到n恰好出现一次。在一次操作中,你会移除所有小于至少一个邻居元素的那些元素。例如,对数组[3, 1, 2, 5, 4]进行一次操作后,你会得到[3, 5]。如果再次进行操作,你会得到[5]。很明显,在进行有限次操作后,你会得到只包含一个整数n的数组。

题目要求:
给定两个整数n和k,找到一个排列使得在进行恰好k次操作后(而不是更早),该排列变为只包含一个元素n的数组。如果不存在这样的排列,则输出-1。

输入数据格式:
第一行包含一个整数t(1≤t≤2000),表示测试用例的数量。
每个测试用例包含一行,有两个整数n和k(2≤n≤100;1≤k≤n-1)。

输出数据格式:
对于每个测试用例,按照以下格式输出答案:
- 如果不存在一个大小为n的排列,在进行恰好k次操作后变为只包含一个元素n的数组,则输出-1;
- 否则,输出n个从1到n的不同的整数,即所请求的排列。如果有多个这样的排列,输出其中任意一个。

例:
输入
```
4
5 2
5 4
2 1
3 2
```
输出
```
3 1 2 5 4
-1
1 2
2 1 3
```题目大意: 这个题目是关于排列的构造问题。给定一个整数n,其排列p是一个数组,其中的每个元素都是1到n之间的整数,且每个整数1到n恰好出现一次。在一次操作中,你会移除所有小于至少一个邻居元素的那些元素。例如,对数组[3, 1, 2, 5, 4]进行一次操作后,你会得到[3, 5]。如果再次进行操作,你会得到[5]。很明显,在进行有限次操作后,你会得到只包含一个整数n的数组。 题目要求: 给定两个整数n和k,找到一个排列使得在进行恰好k次操作后(而不是更早),该排列变为只包含一个元素n的数组。如果不存在这样的排列,则输出-1。 输入数据格式: 第一行包含一个整数t(1≤t≤2000),表示测试用例的数量。 每个测试用例包含一行,有两个整数n和k(2≤n≤100;1≤k≤n-1)。 输出数据格式: 对于每个测试用例,按照以下格式输出答案: - 如果不存在一个大小为n的排列,在进行恰好k次操作后变为只包含一个元素n的数组,则输出-1; - 否则,输出n个从1到n的不同的整数,即所请求的排列。如果有多个这样的排列,输出其中任意一个。 例: 输入 ``` 4 5 2 5 4 2 1 3 2 ``` 输出 ``` 3 1 2 5 4 -1 1 2 2 1 3 ```

加入题单

上一题 下一题 算法标签: