QOJ.ac

QOJ

시간 제한: 2.0 s 메모리 제한: 256 MB 총점: 100

#18541. Devil's Hell deLivery

통계

Devil’s Hell deLivery 公司运送几乎所有东西:箱子、包裹、小包、数据报等等。

从城市 A 到城市 B 的运输过程如下。有 $N$ 辆卡车和 $K$ 件物品。第 $i$ 辆卡车的容量为 $c_i$。第 $j$ 件物品的重量为 $w_j$。卡车进行一次或多次运输步骤。

在一个步骤中,一些物品被装载到一些卡车上。物品不能被拆分。分配给每辆卡车的物品总重量不能超过该卡车的容量。所有卡车同时出发。

在每个步骤结束时,所有卡车都会回到它们出发的地方。如果还有剩余物品,则进行下一步骤。

你的任务是在步骤和卡车之间分配物品,使得步骤数最少。

输入格式

输入包含最多 100 个测试用例。

每个测试用例的第一行包含两个整数 $N$ 和 $K$ ($1 \le N \le 5$, $1 \le K \le 9$):分别表示卡车的数量和物品的数量。

接下来的行包含 $N$ 个整数 $c_1, \dots, c_N$ ($1 \le c_i \le 10^8$):卡车的容量。

再接下来的行包含 $K$ 个整数 $w_1, \dots, w_K$ ($1 \le w_i \le 10^8$):物品的重量。

输出格式

对于每个测试用例,如果无法完成运输,输出单行,包含一个整数 $-1$。

否则,首先输出一行,包含一个整数 $S$:所需的步骤数。该数量必须最小。

之后,输出 $S$ 行描述这些步骤。每个步骤的描述必须以一个整数 $I_i$ 开始,表示该步骤中运送的物品数量。该数量后面必须紧跟 $I_i$ 对 $a_j\ b_j$。每对 $a_j\ b_j$ 表示物品 $a_j$ 被分配给卡车 $b_j$。

如果有多个可能的最佳答案,输出其中任意一个。

样例

输入样例 1

2 4
10 20
5 5 5 5
2 1
10 10
20

输出样例 1

1
4 1 1 2 1 3 2 4 2
-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.