Painter Problem: My code is not working for some cases....what's wrong in my code

My code: on Coding blocks ide

Its passing only few test cases.
what’s wrong, please help…

Thanks in advance