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: SPOJ.com - Problem BOOKS1
Code Link: Online Compiler and IDE - GeeksforGeeks

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. : )