Brief and precise Explanation
IntuitionApproachif robot is at (i, j) then either it will come from (i-1, j) or (i, j-1)
so we need to know the maximum score at this 2 cellswe will store 3 va
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->
if robot is at (i, j) then either it will come from (i-1, j) or (i, j-1)
so we need to know the maximum score at this 2 cells

we will store 3 value in each cell i.e.
score of : 
1. robot hasn't used special ability (dp[i][j][0])
2. robot used special ability 1 time (dp[i][j][1])
3. robot used special ability 2 times (dp[i][j][2])

For this we will use 3D DP array -> size:m*n*3

dp[i][j][0] will store prev cell calue + current cell value as it is
dp[i][j][1] will store maximum of (previousl cell used 1 ability value + current value as it is , previous cell value as it it + Use 1 ability in this cell)
dp[i][j][2] will store maximum of (previousl cell used 2 ability value + current value as it is , previous cell used 1 ability value + Use 1 ability in this cell)

in this previos cells for (i,j) are : (i-1, j) and (i, j-1)

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

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

# Code
```cpp []
class Solution {
public:
    int maximumAmount(vector<vector<int>>& v) {
        int m = v.size(), n = v[0].size();
        vector<vector<vector<int>>> ans(m, vector<vector<int>>(n, vector<int>(3, INT_MIN)));
        ans[0][0][0] = v[0][0];
        ans[0][0][1] = 0;
        ans[0][0][2] = 0;
        for(int i = 1; i < n; i++){
            ans[0][i][0] = ans[0][i-1][0] + v[0][i];
            ans[0][i][1] = ans[0][i-1][1] + v[0][i];
            ans[0][i][2] = ans[0][i-1][2] + v[0][i];
            if(v[0][i] < 0){
                ans[0][i][1] = max(ans[0][i][1], ans[0][i-1][0]);
                ans[0][i][2] = max(ans[0][i-1][1], ans[0][i][2]);
            }
        }
        for(int i = 1; i < m; i++){
            ans[i][0][0] = ans[i-1][0][0] + v[i][0];
            ans[i][0][1] = ans[i-1][0][1] + v[i][0];
            ans[i][0][2] = ans[i-1][0][2] + v[i][0];
            if(v[i][0] < 0){
                ans[i][0][1] = max(ans[i][0][1], ans[i-1][0][0]);
                ans[i][0][2] = max(ans[i-1][0][1], ans[i][0][2]);
            }
        }
        for(int i = 1; i < m; i++){
            for(int j = 1; j < n; j++){
                ans[i][j][0] = max({ans[i-1][j][0], ans[i][j-1][0]}) + v[i][j];
                ans[i][j][1] = max(ans[i-1][j][1] + v[i][j], ans[i][j-1][1] + v[i][j]);
                ans[i][j][2] = max(ans[i-1][j][2]+ v[i][j], ans[i][j-1][2]+ v[i][j]);
                
                if(v[i][j] < 0){
                    ans[i][j][1] = max({ans[i][j][1], ans[i][j-1][0], ans[i-1][j][0]});
                    ans[i][j][2] = max({ans[i-1][j][1], ans[i][j-1][1], ans[i][j][2]});
                }
                
                
                
            }
        }
        int total = max({ans[m-1][n-1][0], ans[m-1][n-1][1], ans[m-1][n-1][2]});
        return total;
    }
};
```
['C++']