Python3: Top-down approach, T.C: O(M*N*2)
Code


# Code
```python3 []
class Solution:
    def maximumAmount(self, coins: List[List[int]]) -> int:
        dp = {}
        rows = len(coins)
        cols = len(coins[0])
        def solve(r,c,cnt):
            if r==rows-1 and c == cols-1:
                return 0 if coins[r][c]<0 and cnt<2 else coins[r][c]
            if r==rows:
                return float('-inf')
            if c==cols:
                return float('-inf')
            if (r,c,cnt) in dp:
                return dp[(r,c,cnt)]
            res = float('-inf')
            res = coins[r][c] + max(solve(r,c+1,cnt), solve(r+1,c,cnt))
            if cnt<2 and coins[r][c] < 0:
                res = max(res,solve(r,c+1,cnt+1),solve(r+1,c,cnt+1))
            # print(r,c,res)
            dp[(r,c,cnt)] = res
            return res
        return solve(0,0,0)
                
                
        
```
['Dynamic Programming', 'Python3']