3D DP solution
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>>& a) {
        int m = a.size() ; 
        int n = a[0].size() ;
        vector<vector<vector<int>>> dp ; 
        dp.resize(m , vector<vector<int>>(n , vector<int>(3, -1))) ; 

        if(a[0][0] >= 0){
            dp[0][0][0] = a[0][0] ;
            dp[0][0][1] = a[0][0] ;
            dp[0][0][2] = a[0][0] ; 
        }else{
            dp[0][0][0] = 0 ;
            dp[0][0][1] = 0 ;
            dp[0][0][2] = a[0][0];
        }

        for(int i = 1 ; i < n ; i++){
            if(a[0][i] >= 0){
                dp[0][i][0] = dp[0][i-1][0] + a[0][i] ;
                dp[0][i][1] = dp[0][i-1][1] + a[0][i] ;
                dp[0][i][2] = dp[0][i-1][2] + a[0][i] ;
            }
            else{
                dp[0][i][0] = max({dp[0][i-1][0] + a[0][i] , dp[0][i-1][1]}) ;
                dp[0][i][1] = max({dp[0][i-1][1] + a[0][i] , dp[0][i-1][2]}) ;
                dp[0][i][2] = dp[0][i-1][2] + a[0][i] ;
            }
        }

        for(int i = 1 ; i < m ; i++){
            if(a[i][0] >= 0){
                dp[i][0][0] = dp[i-1][0][0] + a[i][0] ;
                dp[i][0][1] = dp[i-1][0][1] + a[i][0] ;
                dp[i][0][2] = dp[i-1][0][2] + a[i][0] ;
            }
            else{
                dp[i][0][0] = max({dp[i-1][0][0] + a[i][0] , dp[i-1][0][1]}) ;
                dp[i][0][1] = max({dp[i-1][0][1] + a[i][0] , dp[i-1][0][2]}) ;
                dp[i][0][2] = dp[i-1][0][2] + a[i][0] ;
            }
        }

        for(int i = 1 ; i < m ; i++){
            for(int j = 1 ; j < n ; j++){
                if(a[i][j] >= 0){
                    dp[i][j][0] = max({dp[i-1][j][0] , dp[i][j-1][0]}) + a[i][j] ;
                    dp[i][j][1] = max({dp[i-1][j][1] , dp[i][j-1][1]}) + a[i][j] ;
                    dp[i][j][2] = max({dp[i-1][j][2] , dp[i][j-1][2]}) + a[i][j] ;
                }
                else{
                    dp[i][j][0] = max({dp[i-1][j][1] , 
                                    dp[i][j-1][1] , 
                                    dp[i-1][j][0] + a[i][j] ,
                                    dp[i][j-1][0] + a[i][j]});

                    dp[i][j][1] = max({dp[i-1][j][2] , 
                                    dp[i][j-1][2] , 
                                    dp[i-1][j][1] + a[i][j] ,
                                    dp[i][j-1][1] + a[i][j]});

                    dp[i][j][2] = max({dp[i-1][j][2] + a[i][j] ,
                                    dp[i][j-1][2] + a[i][j]});
                }
            }
        }

        return max({dp[m-1][n-1][0] , dp[m-1][n-1][1] , dp[m-1][n-1][2]}) ; 

    }
};
```
['C++']