QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 32 MB 总分: 120

#16389. KRATKI

统计

大家可能都非常熟悉寻找最长单调子序列的问题。你可能认为自己对此了如指掌。为了说服我们,请解决一个与寻找最长单调子序列“相反”的问题。

给定 $N$ 和 $K$,求一个由 $1$ 到 $N$ 的数字组成的序列,使得其中的每个数字恰好出现一次,且其最长单调子序列(递增或递减)的长度恰好为 $K$。

输入格式

输入的第一行包含整数 $N$ 和 $K$ ($1 \le K \le N \le 10^6$),分别表示序列的长度和所要求的最长单调子序列的长度。

输出格式

如果满足要求的序列不存在,在第一行也是唯一的一行中输出 -1

如果满足要求的序列存在,在第一行也是唯一的一行中输出该序列的 $N$ 个数字。数字之间用单个空格分隔。

满足要求的序列(如果存在)不一定是唯一的,因此你可以输出任何合法的序列。

样例

输入样例 1

4 3

输出样例 1

1 4 2 3

输入样例 2

5 1

输出样例 2

-1

输入样例 3

5 5

输出样例 3

1 2 3 4 5

说明

第一个样例的解释:一个长度为 $4$ 且最长单调子序列长度为 $3$ 的序列是 $(1, 4, 2, 3)$。其最长单调子序列为 $(1, 2, 3)$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.