Paying Up causing an error

Https://www.codechef.com/viewsolution/26627042.
Can anyone tell me which test case is giving me a wrong answer or where is an error in my code