An aerospace test lab certifies a prototype using two rooms: a Wind-Tunnel Chamber and a Pressure Chamber. You must run exactly one certification test in the Wind-Tunnel Chamber and exactly one in the Pressure Chamber. You can only be inside one chamber at a time, but you may choose to run either chamber's test first.
You are given n candidate test slots for the Wind-Tunnel Chamber and m candidate test slots for the Pressure Chamber. Wind-Tunnel slot i has an earliest eligible start time wStart[i] and a fixed duration wDur[i]; Pressure Chamber slot j has an earliest eligible start time pStart[j] and a fixed duration pDur[j]. You start free at time 0. If you are free at time t and you choose to run a slot with earliest eligible start s and duration d, you actually begin at time max(t, s) (waiting if you arrive before the slot opens) and you finish at max(t, s) + d.
Choose exactly one Wind-Tunnel slot, exactly one Pressure Chamber slot, and an order (Wind-Tunnel first or Pressure Chamber first) so that the time at which you finish BOTH tests is as small as possible. Report that minimum possible finish time.
Example 1
Input
2 2 1 3 4 2 2 4 5 1
Expected
6
Explanation
Taking Wind-Tunnel slot 0 (start 1, duration 3) finishes at time 4. Then taking Pressure Chamber slot 1 (earliest start 5, duration 1): you are free at 4 but must wait until 5, finishing at 6. No other slot pair or ordering does better, so the answer is 6.
Example 2
Input
1 1 5 2 1 1
Expected
7
Explanation
Running the Pressure Chamber slot first (start 1, duration 1) finishes at 2; then the Wind-Tunnel slot (earliest start 5) can't begin until 5, finishing at 7. Running the Wind-Tunnel slot first finishes at 7, then the Pressure slot starts at max(7,1)=7 and finishes at 8. The better order is Pressure first, giving 7.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →