Oracle interview question

based on priority queue, dp