QOJ.ac

QOJ

時間限制: 2.0 s 記憶體限制: 1024 MB 總分: 100

#15414. 最高分

统计

Hermione 喜欢玩以下电脑游戏,玩家在游戏中控制一个无序的整数多重集(multiset)。初始时,多重集为空,玩家的分数为 $0$。在游戏的任何时刻,多重集最多包含 $k$ 个整数(不一定两两不同)。在每一步中,玩家可以选择以下操作之一:

  • 插入(Insert):选择整数 $2$ 或 $4$ 并将其插入多重集中。此操作不会改变分数,且仅在操作前多重集的大小严格小于 $k$ 时才允许进行。
  • 合并(Merge):选择一个整数 $x$,使得多重集中至少包含两个 $x$。从多重集中移除两个 $x$,并将一个 $2x$ 插入多重集中。此操作会将 $2x$ 的值累加到玩家的分数中。

玩家可以在任何一步后停止游戏,此时玩家的分数即为最终得分。

Hermione 整个夏天都在度假,已经有一段时间没有玩这个游戏了。今天,她在笔记本电脑上打开游戏,看到了排行榜上她曾获得过的最高分数:按某种顺序排列的 $h_1, h_2, \dots, h_n$。现在她很好奇自己是如何获得这些分数的。

对于每个 $h_i$,求出如果 Hermione 的最终得分为 $h_i$,她在游戏结束时可能拥有的任意一个整数多重集;或者确定无法获得该分数。

输入格式

第一行包含两个整数 $n$ 和 $k$,分别表示排行榜上的分数个数和多重集的最大容量($1 \le n \le 10^4$;$2 \le k \le 16$)。

接下来的 $n$ 行,每行包含一个整数 $h_i$,表示排行榜上的一个分数($1 \le h_i \le 10^9$)。

输出格式

对于每个分数 $h_i$,输出最终多重集的大小 $s$,后跟 $s$ 个整数,以任意顺序描述多重集中的内容($0 \le s \le k$)。必须能够通过该多重集在游戏结束时达到分数 $h_i$。如果有多个答案,输出其中任意一个。

如果无法在游戏结束时获得分数 $h_i$,则输出单个整数 $-1$。

样例

输入样例 1

1 2
12

输出样例 1

1 8

输入样例 2

4 5
4
12
10
20

输出样例 2

2 4 2
5 8 4 2 2 4
-1
3 2 4 8

输入样例 3

1 16
19956

输出样例 3

1 2048

说明

第一个测试样例的一种可能的操作序列如下:

$$\{\} \xrightarrow{\text{插入 } 2} \{2\} \xrightarrow{\text{插入 } 2} \{2, 2\} \xrightarrow{\text{合并, } x = 2, \text{ 分数 } += 4} \{4\} \xrightarrow{\text{插入 } 4} \{4, 4\} \xrightarrow{\text{合并, } x = 4, \text{ 分数 } += 8} \{8\}$$

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.