Top k most frequent numbers

I am not able to understand how to solve this problem and also how can we use heap in this?
Can anybody please explain the logic…

Please refer this. I have explained the approach there.