Update minInd array .
minInd [ 0 ] = preSum [ 0 ] . second ; for ( i = 1 ; i < n ; i ++ ) { minInd [ i ] = min ( minInd [ i - 1 ] , preSum [ i ] . second ) ; } sum = 0 ; for ( i = 0 ; i < n ; i ++ ) { sum = sum + arr [ i ] ;