traverse the array A
for ( int i = 0 ; i < A . length ; i ++ ) { if ( currmax < 0 || ( m . containsKey ( A [ i ] ) && m . get ( A [ i ] ) == 1 ) ) { currmax = 0 ; continue ; } currmax = Math . max ( A [ i ] , A [ i ] + currmax ) ;