QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 512 MB 満点: 100

#9913. Battle of the Peak

統計

There is a one-dimensional space of length $m$ and $n$ items, where the $i$-th item has length $a_i$. Items are placed into the space in order of their index from smallest to largest. For the $i$-th item:

  • If there exists a contiguous empty space of length at least $a_i$ in the current space, you must place the $i$-th item into a contiguous empty space of length $a_i$.
  • Otherwise, the $i$-th item cannot be placed, and you skip it.

You need to output all possible total occupied space lengths after considering all items in order of their index. The total occupied space length is defined as the sum of the lengths of all items that were successfully placed into the space.

Input

The first line contains two integers $m$ and $n$, representing the space length and the number of items, respectively. The second line contains $n$ integers $a_1, \dots, a_n$, representing the lengths of each item in order.

Output

Output two lines. The first line contains an integer $S$, representing the number of possible total occupied space lengths. The second line contains $S$ integers $b_1, \dots, b_S$, outputting all possible total occupied space lengths in increasing order. Note that you must ensure $b_1, \dots, b_S$ are distinct and complete.

Examples

Input 1

8 4
3 4 1 2

Output 1

4
4 6 7 8

Note 1

The figure below shows one possible way to achieve each of the occupied space lengths 4, 6, 7, and 8:

Figure 1: Example 1 explanation

Examples

Input 2

(See 2.in in the problem directory)

Output 2

(See 2.ans in the problem directory)

Subtasks

For all test data, $1 \le m, a_i \le 10^{16}$, $1 \le n \le 14$.

Subtask $n =$ $m, a_i \le$ Score
Subtask 1 5 $10$ 15
Subtask 2 2 $10^{16}$ 5
Subtask 3 3 $10^{16}$ 5
Subtask 4 5 $10^{16}$ 5
Subtask 5 7 $10^{16}$ 5
Subtask 6 9 $10^{16}$ 5
Subtask 7 11 $10^{16}$ 10
Subtask 8 12 $10^{16}$ 10
Subtask 9 13 $10^{16}$ 10
Subtask 10 14 $10^{16}$ 30

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.