I have used a binary search and greedy to solve this problem. Was able to submit at SPOJ but not here.
Here is my code - https://ide.codingblocks.com/s/249113
Along with the right approach, please try to provide some test case this code doesn’t work.
Thankyou.