#P5813. [WC2001] 高性能计算机

[WC2001] 高性能计算机

Problem Description

You now have a time-critical engineering computation task to complete, as the chief engineer of a national high-performance parallel computer. To make full use of the advantages of parallel computing, the computation task should be split into several smaller subtasks.

This large computation task consists of two independent smaller computation tasks, AA and BB. To fully use the computing power of the parallel computer, these tasks need to be decomposed. It is found that both AA and BB can each be divided into many smaller subtasks. The workload of all type AA subtasks is the same, and the workload of all type BB subtasks is also the same (the workloads of type AA and type BB subtasks are not necessarily the same). There is no required execution order between tasks AA and BB, nor among the subtasks.

This supercomputer has pp computing nodes. Each node includes a serial processor, local main memory, and high-speed cache. However, due to long-term use and inconsistent upgrades, the computing abilities of the nodes are not symmetric. A node’s computing ability includes the following aspects:

  1. For this task, each node has three working states: standby, type AA, and type BB. In type AA state it executes type AA tasks; in type BB state it executes type BB tasks; in standby state it does not compute. All processors are in standby before starting work. Switching from any other state into working state AA or BB (including switching between AA and BB) requires a certain startup time. This time may differ across nodes. Use two positive integers tiAt_{i}^{A} and tiBt_{i}^{B} (i=1,2,,pi = 1,2,\cdots,p) to represent the startup time (in ns) for node ii to enter working state AA and working state BB, respectively.

  2. When a node continuously processes tasks of the same type, the execution time (excluding state switching time) grows with the square of the task amount (the number of subtasks of that type), i.e.:

If node ii continuously processes xx type AA subtasks, the corresponding execution time is t=kiAx2t = k_{i}^{A} x^2.

Similarly, if node ii continuously processes xx type BB subtasks, the corresponding execution time is t=kiBx2t = k_{i}^{B} x^2.

Here, kiAk_{i}^{A} and kiBk_{i}^{B} are coefficients in ns, for i=1,2,,pi = 1,2,\cdots,p.

Task assignment must be completed before any computation starts. “Task assignment” means setting a task queue for each computing node. The queue consists of a sequence of type AA and type BB subtasks. The two types of subtasks can be interleaved.

After computation starts, each node reads computation tasks from its own task queue in order and executes them. A consecutive block of same-type subtasks in the queue will be read and executed by that node in one batch, and such a consecutive block cannot be split into two parts for execution.

You need to write a program to schedule the computation tasks for these pp nodes so that the engineering computation task can be completed as early as possible. Assume the schedule will not change after being set, and all nodes start running at the same time. The goal is to make the completion time of the last finishing node as early as possible.

Input Format

The first line describes the computation tasks, containing two positive integers nAn_A and nBn_B, which are the numbers of type AA and type BB subtasks, respectively. The two integers are separated by one space.

The following part describes the computer:

The second line contains an integer pp, the number of computing nodes.

Then follow pp lines describing the nodes in order. Node ii is described on line i+2i+2, which contains four positive integers (separated by one space): tiA,tiB,kiA,kiBt_{i}^{A},t_{i}^{B},k_{i}^{A},k_{i}^{B}.

Output Format

Only one line containing one positive integer: the time from when all nodes start computing until the task is completed.

5 5
3
15 10 6 4
70 100 7 2
30 70 1 6

93

Hint

For all testdata: 1nA601 \le n_A \le 60, 1nB601 \le n_B \le 60, 1p201 \le p \le 20, 1tiA10001 \le t_{i}^{A} \le 1000, 1tiB10001 \le t_{i}^{B} \le 1000, 1kiA501 \le k_{i}^{A} \le 50, 1kiB501 \le k_{i}^{B} \le 50

Translated by ChatGPT 5