6963.Monotone Subsequences

Time Limit: 1s Memory Limit: 512MB

Your task is to create a permutation of numbers $1,2,\dots,n$ whose longest monotone subsequence has exactly $k$ elements.

A monotone subsequence is either increasing or decreasing. For example, some monotone subsequences in $[2,1,4,5,3]$ are $[2,4,5]$ and $[4,3]$ .

Input Format(From the terminal/stdin)

The first input line has an integer $t$ : the number of tests.

After this, there are $t$ lines. Each line has two integers $n$ and $k$ .

  • $1 \le t \le 1000$
  • $1 \le k \le n \le 100$

Output Format(To the terminal/stdout)

For each test, print a line that contains the permutation. You can print any valid solution. If there are no solutions, print IMPOSSIBLE .

Sample Input

Copy
3
5 3
5 2
7 7
 \n
 · \n
 · \n
 · \n

Sample Output special judge

Copy
2 1 4 5 3
IMPOSSIBLE
1 2 3 4 5 6 7
 · · · · \n
          \n
 · · · · · · \n
Source: CSES, Construction Problems, 2215

Submit

请先 登录

© 2025 FAQs