Most Tasks With a Few Pills
tasks[i] is the strength a task needs and workers[j] is the strength of a worker. A worker can do at most one task, and only a task that needs no more than their strength. Each task is done by at most one worker.
You also have pills pills. A pill raises the strength of one worker by boost, and a worker can take at most one.
Return the largest number of tasks that can get done.
Example 1
tasks [5,4]
workers [3,3,4]
pills 1
boost 2
returns 2
The worker of strength 4 does the task that needs 4. One of the others takes the pill, reaches 5, and does the other task.
Example 2
tasks [9]
workers [5,6]
pills 2
boost 2
returns 0
Even with a pill the stronger worker only reaches 8.
Constraints
1 <= len(tasks), len(workers) <= 2000 <= pills <= len(workers)0 <= tasks[i], workers[j], boost <= 10**9
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Sorting and searching problems
- Nesting BoxesHard
- Outline of the SkylineHard
- Shorten the Longest GapHard
- Two Teams of Equal SizeHard
- Height CheckerBeginner
- Kth Largest ElementBeginner
- Kth Smallest Distinct ValueBeginner
- Maximum Product of Two ElementsBeginner