Painter problem-doubt

test cases are giving wrong answer.
please help.
code:https://online.codingblocks.com/player/21656/content/10111/5385

Plz send your code by saving on ide