Painter's Partition Problem

for this code, the 3 and 4 test cases are not passing
but if I sort the array these two test cases pass but 0,2 and 4 give the wrong answer.

u are not allowed to sort the array
Every painter can paint only contiguous segment of boards

try using long long int instead of int