FunctionRacerProblemsRace

Most Tasks With a Few Pills

HardSorting and searchingPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Sorting and searching problems