Wrong Ans in painters partition

my code https://ide.codingblocks.com/#/s/30742
ques link https://hack.codingblocks.com/contests/c/522/716

Here’s a commented solution, do tell in case of chaos

please tell whats wrong in my solution.
output is WA for each and every test case

Thank u very much. All the test cases were passed