3
self, tasks: List[int], workers: List[int], pills: int, strength: int6
from sortedcontainers import SortedList13
# _tasks = SortedList(tasks[:ans])14
_tasks = deque(tasks[:ans])15
_workers = workers[-ans:]18
for worker in _workers:21
# the worker can finish the min task without pill, just move on24
elif worker + strength >= task and remain_pills:25
# the worker cannot finish the min task without pill, but can solve it with pill26
# remove the max task that the strengthened worker can finish instead27
# remove_task_idx = _tasks.bisect_right(worker + strength)28
remove_task_idx = bisect.bisect_right(_tasks, worker + strength)29
# _tasks.pop(remove_task_idx - 1)30
del _tasks[remove_task_idx - 1]36
lo, hi = 0, min(len(workers), len(tasks))38
mid = (lo + hi + 1) // 2