QOJ.ac

QOJ

时间限制: 6 s 内存限制: 1024 MB 总分: 35

#5892. 盒子工厂

统计

你拥有一家拥有两条流水线的工厂。第一条流水线生产盒子,第二条流水线生产放入盒子中的玩具。每种类型的盒子对应一种类型的玩具,反之亦然。

起初,你从第一条流水线取出一个盒子,从第二条流水线取出一个玩具。之后你有以下几种选择:

  • 你可以随时丢弃当前盒子并取下一个盒子。
  • 你可以随时丢弃当前玩具并取下一个玩具。
  • 如果盒子和玩具类型相同,你可以将玩具装入盒子,并将其发送给客户。

你必须按照盒子和玩具被生产出来的顺序依次取用。已知盒子和玩具的生产顺序,请你制定一个策略,使得能够发送给客户的装箱玩具数量尽可能多。

警告:两条流水线生产的盒子和玩具数量非常多。然而,它们倾向于在很长一段时间内只生产同一种产品,然后才会切换。

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 个测试用例。

每个测试用例的第一行包含两个整数 $N$ 和 $M$。接下来一行包含 $2 \times N$ 个整数 $a_1, A_1, a_2, A_2, \dots, a_N, A_N$,再接下来一行包含 $2 \times M$ 个整数 $b_1, B_1, b_2, B_2, \dots, b_M, B_M$。

这意味着第一条流水线将生产 $a_1$ 个类型为 $A_1$ 的盒子,然后是 $a_2$ 个类型为 $A_2$ 的盒子,以此类推,直到生产完 $a_N$ 个类型为 $A_N$ 的盒子。同样地,第二条流水线将生产 $b_1$ 个类型为 $B_1$ 的玩具,接着是 $b_2$ 个类型为 $B_2$ 的玩具,以此类推,直到生产完 $b_M$ 个类型为 $B_M$ 的玩具。

当且仅当盒子和玩具的类型编号相同时,它们才能匹配。

输出格式

对于每个测试用例,输出一行 "Case #x: y",其中 $x$ 是测试用例编号(从 1 开始),$y$ 是你能发送给客户的装箱玩具的最大数量。

数据范围

$1 \le T \le 100$。 $1 \le a_i, b_i \le 10^{16}$。 $1 \le A_i, B_i \le 100$。

子任务 1

$1 \le N \le 3$。 $1 \le M \le 100$。

子任务 2

$1 \le N, M \le 100$。

样例

样例输入 1

4
3 3
10 1 20 2 25 3
10 2 30 3 20 1
3 5
10 1 6 2 10 1
5 1 3 2 10 1 3 2 5 1
3 5
10 1 6 2 10 1
5 1 6 2 10 1 6 2 5 1
1 1
5000000 10
5000000 100

样例输出 1

Case #1: 35
Case #2: 20
Case #3: 21
Case #4: 0

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.