Compare the left and right values
if ( left < right ) ans = max ( ans , ( int ) ( left + maxweight ( s , i , pre ) ) ) ; if ( left == right ) ans = max ( ans , max ( left + maxweight ( s , i , pre ) , right + maxweight ( i + 1 , e , pre ) ) ) ; if ( left > right ) ans = max ( ans , right + maxweight ( i + 1 , e , pre ) ) ;