Painter problem using binary search on monotonic search space

sir, this problem is similar to the book allocation problem but I am not able to pass two test cases out of 6-----I am little confused with the modulo we have to take at the end to print the final answer-----sir can you please see what is wrong with my code----

Ankur, pls share your code by saving on ide… So that I could check it…

I have saved my code at the link https://ide.codingblocks.com/s/229021

Pls refer to this edited code as :