Painter's Partition

Taking the array: 10, 20, 30, 40
I dry ran my algorithm for this problem taking the starting index as 10 because the minimum time is (at least) 10, but I also tried with 40 and 0. They seem to be working as well.

But the code only works when I give the MAXIMUM value in the array as the starting index.

I need to know how I should assign the starting index.