Binary search problem

this is my code for book allocation problem -https://ide.codingblocks.com/s/186124

my code is passing the sample test cases but fails to pass actual test cases .can you please tell what is wrong about the logic?