#P2608. [ZJOI2010] 任务安排
[ZJOI2010] 任务安排
Description
Xiao Y recently encountered a tricky problem. She has two tasks to complete. The first task is to repeat operation 1 (hereinafter referred to as op1) exactly times, and the second task is to repeat operation 2 (hereinafter referred to as op2) exactly times. To complete these tasks, Xiao Y hired workers. For the -th worker, the time to complete one op1 is , and the time to complete one op2 is . Each op1 and op2 can only be completed by one worker, and each worker can only perform one job at any moment.
All workers start working at time . Whenever a worker starts an operation (op1 or op2), they must continue until it finishes and cannot be interrupted. Let the completion time of the first task be , and the completion time of the second task be . Your goal is to schedule the workers so that is minimized.
Input Format
The first line contains an integer , the number of test cases.
For each test case, the first line contains three integers as described above.
Each of the next lines contains two integers , denoting the time the -th worker needs to complete one op1 and one op2, respectively.
Output Format
Output lines. Each line contains a single integer, the minimum value of you can achieve.
4
1 2 3
10 20
3 5 7
10 20
15 16
17 18
4 3 6
10 12
8 9
16 11
13 20
4 4 6
7 12
5 3
6 5
1000000 1000000
100
162
84
41
Hint
Sample Explanation
In the first test case, the only worker first performs op1 times and finishes task 1 at time ( ). Then they perform op2 times and finish task 2 at time ( ). Therefore, the answer is .
In the second test case, worker #1 performs op1 times consecutively and finishes task 1 at time ( ). Worker #2 performs op2 times and finishes task 2 at time ( ). Therefore, the answer is .
The third test case is similar to the second test case.
In the fourth test case, worker #2 first performs op2 times and finishes task 2 at time ( ). Meanwhile, worker #3 performs op1 times and also finishes at time . At this point, one more op1 is still needed, so worker #2 performs the last op1 and finishes task 1 at time ( ). Therefore, the answer is .
Constraints
For of the testdata, , , , and .
Translated by ChatGPT 5
京公网安备 11011102002149号