How can I use a Heap to solve this problem?

Tell Me how to approach this question?