Oracle Interview Question

based on priority queue, dp