Update dp as the maximum value
dp [ i + 1 ] [ h1 ] = max ( dp [ i + 1 ] [ h1 ] , dp [ i ] [ j ] + ( h1 >= l and h1 <= r ) ) NEW_LINE dp [ i + 1 ] [ h2 ] = max ( dp [ i + 1 ] [ h2 ] , dp [ i ] [ j ] + ( h2 >= l and h2 <= r ) ) NEW_LINE ans = 0 NEW_LINE