Read the Pages(Book Allocation) problem

I am getting WA in 2nd test case, though I’m implementing the same logic as discussed in video. I can’t find what exactly I’m doing wrong
My Code: https://ide.codingblocks.com/s/134785
Prateek Bhaiya’s code: https://ide.codingblocks.com/s/134788