#P2751. [IOI 1996 / USACO4.2] 工序安排 Job Processing

[IOI 1996 / USACO4.2] 工序安排 Job Processing

Description

A factory production line is producing a product that requires two types of operations: operation AA and operation BB. Only some machines can perform each operation.

The figure above shows the organization of a production line operating as described below. AA-type machines take workpieces from the input buffer, apply operation AA, and store the resulting intermediate products in the buffer. BB-type machines take intermediate products from the buffer, apply operation BB, and store the final products in the output buffer. All machines work in parallel and independently, and each buffer has unlimited capacity. Each machine may have a different efficiency; a machine requires a fixed amount of time to complete one operation.

Given the processing time of each machine for one operation, compute the minimal total time to finish all AA operations, and the minimal total time to finish all BB operations.

Note:

  1. In one operation, a machine processes exactly one workpiece.
  2. “Total time” means the latest finishing time (makespan).

Input Format

The first line contains three space-separated integers: NN, the number of workpieces (1N10001 \leq N \leq 1000); M1M_1, the number of AA-type machines (1M1301 \leq M_1 \leq 30); M2M_2, the number of BB-type machines (1M2301 \leq M_2 \leq 30).

The second line contains M1M_1 integers, the time each AA-type machine takes to complete one operation; followed by M2M_2 integers, the time each BB-type machine takes to complete one operation. All operation times for AA-type and BB-type machines are integers in [1,20][1, 20].

Output Format

Output a single line with two integers: the minimal total time to complete all AA operations, and the minimal total time to complete all BB operations (AA operations must be completed before BB operations).

5 2 3
1 1 3 1 4
3 5

Hint

Problem translation from NOCOW.

USACO Training Section 4.2.

Translated by ChatGPT 5