FunctionRacerProblemsRace

All Machines Done

HardSorting and searchingPython, JavaScript, TypeScript, Java, C++

You have to start a row of machines, one after another, in any order you like. Setting up machine i takes setup[i] minutes of your time. Once it is set up, it runs on its own for run[i] minutes and is then done. You can set up only one machine at a time, but machines run side by side.

Return the earliest minute by which every machine is done.

Example 1

setup [2,1]
run [1,5]
returns 6

Set up machine 1 first: it runs from minute 1 to minute 6. Machine 0 is set up by minute 3 and done at minute 4. The other order ends at minute 8.

Example 2

setup [3]
run [4]
returns 7

Three minutes of setup, then four minutes of running.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Sorting and searching problems