Software Company
Time limit1sMemory limit128 MB
Assign m subprojects of each of two projects to n employees, who work sequentially, to minimize the largest total working time.
- Level
Hard8 of 10
- Topics
- Binary search, Greedy, Dynamic programming, Sorting
- Solved
- No attempts yet
Problem
A software development company has been assigned two programming projects. Because both projects belong to the same contract, they must be delivered at the same time; finishing one earlier does not help.
The company has employees available for the work. To make the two projects easier to manage, each project is split into independent subprojects. A single subproject can be worked on by only one employee at a time, but different subprojects of the same project may be handled by different employees simultaneously.
An employee may take on several subprojects and processes them sequentially, so that employee's working time is the sum of the durations of the subprojects assigned to them. The goal is to finish both projects as early as possible — that is, to minimize the moment at which the last subproject is completed (the largest total working time among all employees).
Input
The first line contains the number of test cases (). The test cases follow.
The first line of each test case contains two integers () and (). The next lines each contain two integers and : is the time in seconds employee needs to finish one subproject of the first project, and is the time in seconds the same employee needs to finish one subproject of the second project.
Output
For each test case, print on its own line a single integer: the minimum time in seconds after which both projects can be completed.