Multi-Machine Scheduling of Two Applications
Time limit5sMemory limit256 MB
Ellie assigns the ordered steps of two applications to M machines with different per-step times to minimize the time the last step finishes.
- Level
Hard8 of 10
- Topics
- Binary search, Greedy, Math
- Solved
- No attempts yet
Problem
Ellie wants to finish two applications as early as possible. Application () consists of identical steps numbered from to . Her cluster holds machines numbered from to , and she runs the steps of both applications on them. The machines differ in speed: running one step of application on machine takes seconds.
Every step is CPU heavy, so a machine runs at most one step at a time. If several steps are assigned to one machine, their execution intervals must not overlap, and they may touch only at endpoints. A running step cannot be paused and resumed later either. Once a step starts, Ellie either lets it finish or cancels it before completion and runs it again from the beginning later, on the same machine or on another one.
Because of data dependencies, the steps of one application run in order. Step of application starts at the moment step of that application finished, or later. Step may run on the machine that ran step or on any other machine. Steps of different applications do not depend on each other.
Ellie can start executing steps at time . She wants the moment (in seconds) when the last step of either application finishes to be as small as possible. Print the minimum possible value of .
Input
The first line contains the number of test cases . The test cases follow, each on three lines. The first line holds the integers , and . The second line holds the integers , , ..., in this order. The third line holds the integers , , ..., in this order.
Output
For each test case, in the order given in the input, print the minimum possible value of on its own line.
Notes
With a single machine, every step of both applications runs on it one after another, so is the sum of the two execution times.
If the two applications use one machine each, is the larger of the two execution times. When both applications want the same machine, one of them has to work on a machine that is slower for it.
Once an application finishes, its machine becomes free and the other application can move there. Take , , , , , , . Running every step of application 1 on machine 1 finishes it at time . Application 2 runs its first steps on machine 2 and finishes them at time , waits until machine 1 is free, and runs its last step on machine 1, finishing at time . Keeping the last step on machine 2 would end at , so the move is faster.
Sometimes the fastest plan lets both applications share one machine over disjoint time intervals while each of them moves across several machines.