Painters partition Problem

some of the test case not pass please help me out