🌟🧠💡O(n*m) Striver Style DP on GRID SOLUTION 🌟🧠💡
Complexity

Time complexity:
O(n∗m)


Space complexity:
O(n∗m)

Code
# Complexity
- Time complexity:
$$O(n*m)$$

- Space complexity:
$$O(n*m)$$

# Code
```cpp []
class Solution {
public:
    int n,m;
    int solve(int x,int y,int power_left,vector<vector<int>> &arr,vector<vector<vector<long long>>> &dp)
    {
        if(x>=n || y>=m || x<0 || y<0 || power_left<0) return -1e9;
        if(x==n-1 && y==m-1)
        {
            if(arr[x][y]>=0) return arr[x][y];
            else if(power_left) return 0;
            else return arr[x][y];
        }
        if(dp[x][y][power_left]!=LLONG_MIN) return dp[x][y][power_left];
        long long right=-1e9;
        long long down=-1e9;
        right=max(right,0LL+arr[x][y]+solve(x,y+1,power_left,arr,dp));
        down=max(down,0LL+arr[x][y]+solve(x+1,y,power_left,arr,dp));
        if(power_left && arr[x][y]<0)
        {
            right=max(right,0LL+solve(x,y+1,power_left-1,arr,dp));
            down=max(down,0LL+solve(x+1,y,power_left-1,arr,dp));
        }
        return dp[x][y][power_left]=max(right,down);
    }
    int maximumAmount(vector<vector<int>>& arr) 
    {
        n=arr.size();
        m=arr[0].size();
        vector<vector<vector<long long>>> dp(n+1,vector<vector<long long>>(m+1,vector<long long>(3,LLONG_MIN)));
        return solve(0,0,2,arr,dp);
    }
};
```
['Dynamic Programming', 'C++']