Unable to clear test case 2

I’m unable to figure out the problem in my binary search function.


this is my submitted solution on spoj, u can refer to this, i would advice u to solve the book allocation problem before moving on to this