TLE in Hussain Set problem

I’m new here, my sincere apologies if i make any mistake.
So, i was doing this problem (https://www.codechef.com/problems/COOK82C) but it is showing a TLE.
I used heap in my solution (https://ideone.com/B9dubF) and well commented it.
I think it should run as it have a time complexity of O(k*logn).
Can anyone help me in this?
Thanks in advance :slight_smile: