FunctionRacerProblemsRace

Saw, Then Paint

HardGreedyPython, JavaScript, TypeScript, Java, C++

A workshop has one saw and one paint booth. Job i needs jobs[i][0] hours at the saw and after that jobs[i][1] hours in the booth.

Each machine works on one job at a time without a break in between. The jobs go through the saw in an order you choose, and through the booth in that same order. A sawn job may wait for the booth.

Both machines are free at time 0. Return the earliest time by which every job is painted.

Example 1

jobs [[3,2],[1,4]]
returns 7

Job [1, 4] first: it is sawn at 1 and painted at 5. Job [3, 2] is sawn at 4, waits for the booth and is painted at 7. The other order ends at 9.

Example 2

jobs [[2,2]]
returns 4

Two hours at the saw, then two in the booth.

Example 3

jobs [[5,1],[4,1],[1,1]]
returns 11

The saw alone is busy until 10, and the last job still needs an hour of paint.

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 Greedy problems