Trains the technique from
LeetCode 502IPOThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A repair workshop has a board of n jobs it could take on and enough staff to finish at most max_jobs of them. Job i pays payouts[i] once it is delivered, but the shop will only be handed the job if it already has at least setup[i] in the bank, because that is the value of loan equipment the job needs.
The shop starts with funds in the bank. Taking a job does not spend anything: the setup figure is only a threshold the bank balance has to clear, and the payout is added to the balance as soon as the job is finished. Jobs are worked one after another, so a payout is available before choosing the next job, and each job can be taken at most once.
Choose at most max_jobs jobs to end up with as much money in the bank as possible, and return that final balance. The shop may also stop early, or take no jobs at all, if nothing on the board is within reach.
Example 1
With 3 in the bank, jobs 0 and 2 are within reach. Taking job 0 pays 5 and brings the balance to 8, which now clears job 1's threshold of 6. Taking job 1 pays 8 for a final balance of 16, and that is two jobs.
Example 2
An empty bank only clears job 0's threshold of 0, so the single job taken pays 4.
Example 3
Job 0 pays 3, taking the balance to 5, and job 1 pays 1, taking it to 6. Job 2 needs 12 in the bank, so the shop stops after two of its four allowed jobs.
Example 4
Both thresholds are above the starting balance of 0, so no job can be handed over and the balance stays at 0.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def max_funds(max_jobs: int, funds: int, payouts: list[int], setup: list[int]) -> int:public int maxFunds(int maxJobs, int funds, int[] payouts, int[] setup)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.