DP using memoization
IntuitionStandard DP Question (top left to right bottom , down or right)
using memoizationApproachCase 1) coins[i][j] >= 0
a) take and move to right column
b) t
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Standard DP Question (top left to right bottom , down or right)
using memoization
# Approach
<!-- Describe your approach to solving the problem. -->
Case 1) coins[i][j] >= 0
    a) take and move to right column
    b) take and move to bottom row
Case 2) coins[i][j] < 0
    a) don't neutralize(we will save for maybe future as we can at max neutralize 2 negative coins[i][j]) and move right.
    b) don't neutralize and move down.
    c) neutralize and move to right(only 1 neutralizing option remains so decreament the cnt).
    d) neutralize and move to down.
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
TC: O(n * m * 3) ~ O(n*m)

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

# Code
```cpp []
#include <bits/stdc++.h>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <cwchar>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <ostream>
#include <pthread.h>
#include <queue>
#include <set>
#include <stack>
#include <sys/types.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

template <typename a, typename B>
ostream &operator<<(ostream &os, const pair<a, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<
                                    !is_same<T_container, string>::value,
                                    typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v) {
  os << '{';
  string sep;
  for (const T &x : v)
    os << sep << x, sep = ", ";
  return os << '}';
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i, m, n) for (ll i = m; i < n; i++)
#define vll vector<ll>
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;

class Solution {
private:
    int f(int i, int j, int cnt, vector<vector<int>>& coins, int n, int m, vector<vector<vector<int>>>& dp) {
        if (i == n - 1 && j == m - 1) {
            if (cnt < 2) {
                if(coins[i][j] >= 0) return coins[i][j];
                else return 0;
            } else {
                return coins[i][j];
            }
        }

        if (i >= n || j >= m) return -1e8;

        if (dp[i][j][cnt] != -1) return dp[i][j][cnt];

        if (coins[i][j] >= 0) {
            int take1 = coins[i][j] + f(i, j + 1, cnt, coins, n, m, dp);
            int take2 = coins[i][j] + f(i + 1, j, cnt, coins, n, m, dp);
            return dp[i][j][cnt] = max({take1, take2});
        }

        int neutralize1 = -1e8 , neutralize2 = -1e8;
        if (coins[i][j] < 0) {
            int notNeutralize1 = coins[i][j] + f(i, j + 1, cnt, coins, n, m, dp);
            int notNeutralize2 = coins[i][j] + f(i + 1, j, cnt, coins, n, m, dp);
            if(cnt < 2) neutralize1 = 0 + f(i, j + 1, cnt + 1, coins, n, m, dp);
            if(cnt < 2) neutralize2 = 0 + f(i + 1, j, cnt + 1, coins, n, m, dp);
            return dp[i][j][cnt] = max({notNeutralize1, notNeutralize2, neutralize1, neutralize2});
        }

        return dp[i][j][cnt] = 0;
    }

public:
    int maximumAmount(vector<vector<int>>& coins) {
        int n = coins.size();
        int m = coins[0].size();
        vector<vector<vector<int>>> dp(n, vector<vector<int>>(m, vector<int>(3, -1)));
        return f(0, 0, 0, coins, n, m, dp);
    }
};
```
['C++']