#P3212. [HNOI2011] 任务调度

    ID: 2261 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>搜索2011各省省选湖南随机贪心,随机化

[HNOI2011] 任务调度

Description

There are nn tasks and two machines, A and B. Each task must be processed on both machines.

The ii-th task requires time aia_i on machine A and time bib_i on machine B. The goal is to finish all tasks on both A and B while minimizing the total time to complete all tasks. However, some tasks have restrictions on whether they must be processed on A first or on B first. Based on this, all tasks are divided into three categories:

  1. The task must be processed on machine A first, then on machine B.
  2. The task must be processed on machine B first, then on machine A.
  3. The task has no restriction and may be processed on machine A first or on machine B first.

Given each task’s category and its processing times on machines A and B, find the minimum total time required to finish all tasks according to the rules.

Input Format

The first line contains a single positive integer nn, the number of tasks.

Each of the next nn lines contains three space-separated positive integers ti,ai,bit_i, a_i, b_i, denoting the category of task ii (categories 11, 22, and 33 are as defined above) and the processing times of task ii on machines A and B, respectively.

Output Format

Output a single integer, the minimum total time required to finish all tasks.

3
3 5 7
1 6 1 
2 2 6

14

Hint

Sample 1 Explanation:

One optimal scheduling plan is:

On machine A, schedule the tasks in order: Task 1 (05)1\ (0\to 5), task 2 (511)2\ (5\to 11), task 3 (1113)3\ (11\to 13);

On machine B, schedule the tasks in order: Task 3 (06)3\ (0 \to 6), task 1 (613)1\ (6 \to 13), task 2 (1314)2\ (13 \to14),

so the total time required to finish all tasks is 1414.

Constraints:

For 100%100\% of the testdata, it is guaranteed that 1n201 \le n \le 20, 1ai1031 \le a_i \le 10^3, 1ti31 \le t_i \le 3, and the number of tasks with ti=3t_i = 3 does not exceed 1010.

Translated by ChatGPT 5