Backlog after k drains
Your task
Each worker queue on a busy server has a backlog measured in pending jobs. You are allowed to run a drain routine exactly k times. Each run picks one queue and removes floor(b / 2) jobs from it, where b is that queue's current backlog. To shrink the total backlog fastest, every run should target the queue with the largest current backlog. Return the total backlog remaining after the k runs. Example: queues = [5, 4, 9], k = 2 gives 12, drain 9 to 5, then drain a 5 to 3, leaving 3 + 4 + 5.
Examples
remaining_backlog(queues: list[int], k: int) -> intExample 1
Input
remaining_backlog([5, 4, 9], 2)Output
12