Most Workshops Before Their Deadlines
Workshop i takes hours[i] hours of continuous work and must be finished no later than hour closes[i]. You start at hour 0 and work on workshops one at a time, one after another without overlap, in any order you choose; finishing exactly at a workshop's closing hour is fine. You may skip any workshops. Return the largest number of workshops you can finish on time. Return 0 for an empty list.
Example 1
Do the 10-hour workshop (done at 10, closes 20), then the 100-hour one (done at 110, closes 125), then the 20-hour one (done at 130, closes 130). The 200-hour one cannot fit with those three, and no set of four works.
Example 2
Done in order, the workshops finish at hours 5, 10 and 15, each exactly at its closing hour.
Constraints
0 <= len(hours) == len(closes) <= 1001 <= hours[i] <= 1001 <= closes[i] <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Greedy problems
- Narrowest SpreadHard
- Saw, Then PaintHard
- Seat the Pairs TogetherHard
- Two From Every IntervalHard
- Coins Handed BackBeginner
- Coins on the TableBeginner
- Fewest BanknotesBeginner
- Fewest JugsBeginner