Maximum Profit in Job Scheduling
Real-world version: Studio Booking PayoutThe statement here is our own: the same inputs, outputs and technique.
A recording studio has a stack of booking requests to answer. Request i wants the room from hour start[i] until hour finish[i] and pays payout[i] if it is accepted.
The room holds one session at a time, so two accepted requests may not overlap. Requests that merely touch are fine: a request that ends at hour t can be followed by one that begins at hour t, because the engineer resets the room instantly.
Accept any collection of requests you like, subject to that rule, and return the largest total payout obtainable. Accepting nothing is allowed but never necessary, since every payout is positive.
Examples
Example 1
- Input
- start = [1, 3], finish = [3, 5], payout = [6, 6]
- Output
- 12
The second request begins on the hour the first one ends, so both fit and the studio collects everything.
Example 2
- Input
- start = [1, 1, 3], finish = [10, 3, 6], payout = [20, 12, 12]
- Output
- 24
Two shorter back-to-back sessions beat the single long one that pays 20 and blocks the whole day.
Example 3
- Input
- start = [1, 2, 3], finish = [8, 7, 9], payout = [5, 9, 3]
- Output
- 9
Every pair of requests overlaps here, so only the best paying one can be taken.
Constraints
- 1 <= start.length == finish.length == payout.length <= 5 * 10^4
- 1 <= start[i] < finish[i] <= 10^9
- 1 <= payout[i] <= 10^4
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def max_payout(start: list[int], finish: list[int], payout: list[int]) -> int:public int maxPayout(int[] start, int[] finish, int[] payout)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 9 test cases: 9 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Two Best Non-Overlapping EventsReal-world version: Two Studio BookingsMedium
- Number of Matching SubsequencesReal-world version: Labels That Read Through the TapeMedium
- Minimize the Maximum Difference of PairsReal-world version: Pairing Gears by Closest Tooth CountMedium
- Maximum Earnings From TaxiReal-world version: Booking the Tram Along the LineMedium