Unable to get the logic?

I am trying to solve this problem http://www.spoj.com/problems/PRATA/ but unable to get the logic,I seen the comments some solved it using binary search and min-heap any one help me :slight_smile: