QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100
Statistics

Rie 喜欢制作饼干。她制作了 $N$ 种饼干,其中第 $i$ 种饼干有 $A_i$ 个 ($1 \le i \le N$)。为了售卖这些饼干,她需要将它们装入盒中。装盒需要满足以下条件:

  • 每个盒子中饼干的种类必须各不相同。
  • 每个盒子中饼干的数量必须等于以下 $M$ 个数中的一个:$B_1, B_2, \dots, B_M$。

请编写一个程序,给定 Rie 制作的饼干信息以及装盒条件,判断是否可以将所有饼干装入盒中。如果可以,请输出一种使用最少盒子数量的装盒方案。

输入格式

从标准输入读取以下数据:

$N$ $A_1 \ A_2 \ \dots \ A_N$ $M$ $B_1 \ B_2 \ \dots \ B_M$

输出格式

如果可以将所有饼干装入盒中且满足条件,设 $x$ 为使用的盒子数量,$c_k$ 为第 $k$ 个盒子中饼干的数量 ($1 \le k \le x$),$v_{k,1}, v_{k,2}, \dots, v_{k,c_k}$ 为第 $k$ 个盒子中饼干的种类。请按以下格式输出:

$x$ $c_1 \ v_{1,1} \ v_{1,2} \ \dots \ v_{1,c_1}$ $c_2 \ v_{2,1} \ v_{2,2} \ \dots \ v_{2,c_2}$ $\vdots$ $c_x \ v_{x,1} \ v_{x,2} \ \dots \ v_{x,c_x}$

其中使用的盒子数量 $x$ 必须是最小可能的数量。如果存在多种满足条件的装盒方案,输出其中任意一种即可。

如果无法将所有饼干装入盒中并满足条件,请向标准输出写入 -1。

数据范围

  • $1 \le N \le 15\,000$
  • $A_i \ge 1$ ($1 \le i \le N$)
  • $A_1 + A_2 + \dots + A_N \le 15\,000$
  • $1 \le M \le N$
  • $1 \le B_j \le N$ ($1 \le j \le M$)
  • $B_j < B_{j+1}$ ($1 \le j \le M - 1$)
  • 所有输入值均为整数。

子任务

  1. (6 分) $N \le 500, A_i = 1$ ($1 \le i \le N$)。
  2. (7 分) $N \le 500, M = 1$。
  3. (12 分) $A_1 + A_2 + \dots + A_N \le 15$。
  4. (45 分) $A_1 + A_2 + \dots + A_N \le 500$。
  5. (15 分) $A_1 + A_2 + \dots + A_N \le 3\,000$。
  6. (15 分) 无附加限制。

样例

样例输入 1

7
1 1 1 1 1 1 1
3
1 2 3

样例输出 1

3
2 1 7
2 2 6
3 3 4 5

样例输入 2

5
5 3 1 2 4
1
4

样例输出 2

-1

样例输入 3

7
5 4 4 2 1 1 1
2
2 6

样例输出 3

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

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.