Condition if current element is greater than mx then make the element - infinity
if arr [ j ] > mx : NEW_LINE INDENT val = - INF NEW_LINE DEDENT else : NEW_LINE INDENT val = arr [ j ] ; NEW_LINE DEDENT curr += val NEW_LINE if ( curr < 0 ) : NEW_LINE INDENT curr = 0 NEW_LINE DEDENT if ( curr > ans ) : NEW_LINE INDENT ans = curr NEW_LINE DEDENT