how to solve this question with binary search and priority queue?

Please Explain your approach in detail
Problem Link-link text

//