QOJ.ac

QOJ

时间限制: 1 s 内存限制: 64 MB 总分: 120

#13693. 卡片

统计

“拿着这些牌,我跟你说,这是我瑞典的表哥在战争饥荒最严重的时候寄给我的,当时我们一直待在战壕里打拉米牌。”

丹尼尔:“我们要玩拉米牌吗,嗯?”

多马戈伊:“好吧,那就玩吧。”

丹尼尔:“现在看好了。你有一叠共 $N$ 张牌,其中第 $i$ 张牌上写着一个声明:‘在这张牌下方的牌中,至少有 $a_i$ 张牌包含虚假声明。’你需要重新排列它们,使得整叠牌中恰好有 $K$ 张牌包含虚假声明。”

多马戈伊:“你每次玩这个游戏都把我虐得体无完肤,你从哪弄来这些牌的,老弟?!”

丹尼尔:“啊,我老爸组织扑克比赛,所以他每天都给我免费的牌,每副牌值十块钱呢。”

你的任务是帮助多马戈伊解决丹尼尔提出的任务。输出多马戈伊必须放置卡牌的顺序。也有可能这只是丹尼尔的一个恶作剧,根本不存在任何可能的放牌顺序。在这种情况下,输出 -1

输入格式

第一行包含两个整数 $N$ 和 $K$($1 \le N \le 5 \cdot 10^5$,$0 \le K \le N$)。

接下来的 $N$ 行中,第 $i$ 行包含一个整数 $a_i$($0 \le a_i \le 5 \cdot 10^5$)。

输出格式

如果所需的顺序不存在,输出 -1

否则,在单行中输出 $N$ 个由空格隔开的整数,表示卡牌上的数字,按从牌堆顶部到牌堆底部的顺序排列。如果有多个解,输出其中任意一个。

子任务

在占总分 30% 的测试数据中,满足 $N \le 16$。

在另外占总分 40% 的测试数据中,满足 $N \le 2000$。

样例

输入样例 1

4 2
1
2
2
3

输出样例 1

2 3 1 2

输入样例 2

5 3
2
1
3
0
3

输出样例 2

3 3 0 1 2

输入样例 3

6 4
0
2
5
2
0
1

输出样例 3

-1

说明

第二个样例的解释:

为了简单起见,我们根据卡牌上写着的声明,将卡牌标记为“真”或“假”。

  • 第五张牌下方有 $0$ 张假牌,因此它是假的。
  • 第四张牌下方有 $1$ 张假牌,因此它是真的。
  • 第三张牌下方有 $1$ 张假牌,因此它是真的。
  • 第二张牌下方有 $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.