If the previous difference is positive
if ( rightDP > 0 ) rightDP = rightDiff + rightDP ; else rightDP = rightDiff ; } c ++ ; } int maxi = 0 ; for ( int i = 0 ; i < n / 2 ; i ++ ) { maxi = max ( maxi , max ( leftDP [ i ] , rightDP [ i ] ) ) ; } return maxi + sum ; }