sum from 1 to i elements of arr
for ( int i = 1 ; i <= n ; i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i - 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) dp [ 1 ] [ i ] = sum [ i ] ; and using it to calculate the result as : best = min ( best , max ( dp [ i - 1 ] [ p ] , sum [ j ] - sum [ p ] ) ) ;