Condition to check if the current cell is the bottom - right cell of the matrix
if ( i == n - 1 and j == m - 1 ) : NEW_LINE INDENT if ( val > v [ i ] [ j ] ) : NEW_LINE INDENT dp [ i ] [ j ] = MAX NEW_LINE return MAX NEW_LINE DEDENT else : NEW_LINE INDENT dp [ i ] [ j ] = v [ i ] [ j ] - val NEW_LINE return dp [ i ] [ j ] NEW_LINE DEDENT DEDENT