head_workers and tail_workers with the first m and last m workers respectively.next_head = m and next_tail = n - m - 1 to track the next worker to be added to the queues.k hiring sessions:
a. Compare the top workers of both queues and hire the one with the lowest cost.
b. If both workers have the same cost, hire the worker from head_workers.
c. Add the cost of the hired worker to the total cost.
d. If next_head <= next_tail, refill the queue from which the worker was hired:
head_workers, add costs[next_head] and increment next_head.tail_workers, add costs[next_tail] and decrement next_tail.k hiring sessions.