Easy understanding python solution 100% beats solution
Complexity
Time complexity: O(n∗m∗2)

Space complexity: O(n∗m∗2)
Code
![image.png](https://assets.leetcode.com/users/images/0fd02be9-1b49-4bd5-9dc0-24dc27bc0325_1736655739.4018486.png)


# Complexity
- Time complexity: $$O(n*m*2)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: $$O(n*m*2)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def maximumAmount(self, coins: List[List[int]]) -> int:
        n = len(coins)
        m = len(coins[0])
        memo = {}
        def recur(i,j, sac):
            if i >= n or j >= m:
                return -float('inf')

            if i==n-1 and j == m-1:
                if sac > 0 and coins[i][j] < 0:
                    return 0
                return coins[i][j]

            if (i,j,sac) in memo:
                return memo[(i,j,sac)]
    
            right = -float('inf')
            if coins[i][j] < 0 and sac > 0:
                right = max(right,recur(i,j+1,sac-1))
            right = max(right,coins[i][j] + recur(i,j+1,sac))
    
            down = -float('inf')
            if coins[i][j] < 0 and sac > 0:
                down = max(down,recur(i+1,j,sac-1))
            down = max(down,coins[i][j]+recur(i+1,j,sac))

            memo[(i,j,sac)] = max(right,down)
            return max(right,down)

        
        return recur(0,0,2)
        
```
['Python3']