What's wrong with this code

My code is passing the sample test cases of the Getting Books question on Spoj yet I am receiving WA as verdict.
Question link: https://www.spoj.com/problems/BOOKS1/
Code Link: https://ide.geeksforgeeks.org/XswRU02wWo

Hey, there’s a small mistake. It should be print(ans, v, k); instead of print(mid, v, k); in line 64. Got accepted after that. : )