BEATS100%||C++
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

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

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

# Code
```cpp []
class Solution {
public:
    int maximumAmount(vector<vector<int>>& coins) {
        int constant = -300000;
        int m = coins.size();
        int n = coins[0].size();
       // cout<<m<<" "<<n<<endl;
        vector<vector<vector<int>>>dp(3 , vector<vector<int>>(m , vector<int>(
            n  , constant)));
        for(int i=0; i<m; i++)
        {
            for(int j =0; j<n; j++)
            {
             if(i == 0 && j == 0)
             {
                if(coins[0][0] >= 0)
                {
                   dp[0][0][0] = coins[0][0];
                }
                else
                {
                    dp[0][0][0] = coins[0][0];
                    dp[1][0][0] = 0;
                }
             }
             else if(i ==0)
             {
                if(coins[i][j] >= 0)
                {
                    for(int k =0; k<3; k++)
                    {
                        dp[k][i][j] = dp[k][i][j-1] + coins[i][j]; 
                    }
                }
                else
                {
                    dp[0][i][j] = dp[0][i][j-1] + coins[i][j];
                    dp[1][i][j] = max(dp[0][i][j-1], dp[1][i][j-1]+ coins[i][j]);
                    dp[2][i][j] = max(dp[2][i][j-1] + coins[i][j] , dp[1][i][j-1]);
                     
                }
             }
             else if(j == 0)
             {
                if(coins[i][j] >= 0)
                {
                    for(int k =0; k<3; k++)
                    {
                        dp[k][i][j] = coins[i][j] + dp[k][i-1][j];
                    }
                }
                else
                {
                    dp[0][i][j] = coins[i][j] + dp[0][i-1][j];
                    dp[1][i][j] = max(dp[0][i-1][j] , dp[1][i-1][j] + coins[i][j]);
                    dp[2][i][j] = max(dp[1][i-1][j] , dp[2][i-1][j] + coins[i][j]);
                }
             } 
             else
             {
                if(coins[i][j] >= 0)
                {
                    for(int k = 0; k < 3; k++)
                    {
                        dp[k][i][j] = coins[i][j] + max(dp[k][i-1][j] , dp[k][i][j-1]);
                    }
                }
                else
                {
                dp[0][i][j] = max(coins[i][j] + dp[0][i-1][j] ,dp[0][i][j-1] + coins[i][j]);
                dp[1][i][j] = max(max(dp[0][i][j-1], dp[1][i][j-1] + coins[i][j]),
                              max(dp[0][i-1][j] , dp[1][i-1][j] + coins[i][j]));
                dp[2][i][j] = max(max(dp[1][i-1][j] , dp[2][i-1][j] + coins[i][j]),
                              max(dp[2][i][j-1] + coins[i][j] , dp[1][i][j-1]));
                }
             } 
            }
        }
        return max(dp[1][m-1][n-1] , max(dp[0][m-1][n-1] , dp[2][m-1][n-1]));
    }
};
```
['C++']