Painter's problem

solution: https://ide.codingblocks.com/s/314028
I’m unable to tackle the unit time.
please help