QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#1753. 不正当交易

统计

本周你在利兹找到了一份扑克发牌员的新工作。你的任务是为游戏分发牌。底薪并不高,但你发现如果牌发得好,可以从客人的小费中赚到不少钱。

最慷慨的顾客希望他们的对手在牌桌上拿到的牌中,不会出现数字相同的对子;为了让他们满意,你必须确保这种情况永远不会发生。

你已经知道了牌堆中每张牌的数字,以及每个玩家手中必须持有的牌数。请计算在不出现对子的情况下,你一次最多可以发出多少手牌。

图 C.1:样例输入 2 的解法示意图。

输入格式

输入包含: 一行包含两个整数 $n$ 和 $h$ ($1 \le h \le n \le 10^6$),分别表示牌堆中的牌数和每手牌的张数。 一行包含 $n$ 个整数 $v_1, \dots, v_n$ ($1 \le v_i \le 10^6$,对于所有 $i$),表示牌上的数字,顺序不固定。

输出格式

如果无法在不出现对子的情况下发出任何手牌,输出 impossible

否则,输出 $k$ 行(其中 $k$ 是最多能发出的手牌数),每行包含来自输入的 $h$ 个数字。你使用任何数字的次数不得超过它在 $v$ 中出现的次数。

如果存在多个达到最大值 $k$ 的答案,你可以输出其中任意一个。

样例

输入 1

6 3
1 2 1 2 3 4

输出 1

1 2 4
1 2 3

输入 2

14 3
3 4 1 1 1 2 3 1 2 1 1 5 6 7

输出 2

6 1 3
2 4 1
5 1 2
1 3 7

输入 3

8 5
1 1 2 2 3 3 4 4

输出 3

impossible

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.