QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#12820. 子序列和

Statistics

Yuta 有一个包含 $n$ 个正整数的序列 $A_1, \dots, A_n$,它们的和为 $m$。对于 $A$ 的每一个子序列 $S$,他计算了该子序列中所有元素的和。

现在,Yuta 得到了 $2^n$ 个介于 $0$ 和 $m$ 之间的整数。对于每个 $i \in [0, m]$,令 $B_i$ 为他得到的整数中等于 $i$ 的个数。

Yuta 向你展示了数组 $B$,并要求你还原出 $A_1, \dots, A_n$。如果存在多种可能性,请找出字典序最小的序列。

输入格式

第一行包含两个整数 $n$ 和 $m$ ($1 \le n \le 50, 1 \le m \le 10^4$)。

第二行包含 $m + 1$ 个整数 $B_0, \dots, B_m$ ($0 \le B_i \le 2^n$)。

输出格式

输出一行,包含 $n$ 个整数 $A_1, \dots, A_n$。

题目保证至少存在一个解。如果有多个可能的解,请输出字典序最小的那一个。

样例

样例输入 1

2 3
1 1 1 1

样例输出 1

1 2

样例输入 2

3 3
1 3 3 1

样例输出 2

1 1 1

说明

在第一个样例中,$A$ 为 $[1, 2]$。$A$ 有四个子序列 $[]$、$[1]$、$[2]$ 和 $[1, 2]$,它们的和分别为 $0, 1, 2, 3$。因此,$B = [1, 1, 1, 1]$。

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.