C++ beats 100%, simple math
IntuitionApproachFor each index i, compute the maximum profit loss without ith transaction, that is, maximize this : costi​−∑j=i​(backj​−costj​)Complexity

Tim
# Intuition

# Approach
For each index $$i$$, compute the maximum profit loss without $$i$$th transaction, that is, maximize this : $$cost_i-\sum_{j \neq i}(back_j-cost_j)$$

# Complexity
- Time complexity:
$$O(n)$$

- Space complexity:
$$O(1)$$

# Code
```cpp []
class Solution {
public:
    long long minimumMoney(vector<vector<int>>& transactions) 
    {
        int n = transactions.size();
        long long M = 0;
        long long N = 0;
        for(int i = 0; i < n; ++i)
        {
            M = max(1LL*transactions[i][0],M);
            if(transactions[i][1]<transactions[i][0])
            {
                N += transactions[i][1] - transactions[i][0];
            }
        
        }
        for(int i = 0; i < n; ++i)
        {
            long long c = 1LL*transactions[i][0];
            long long b = 1LL*transactions[i][1];
            if(b<c) M = max(M,-N+b);
            else M = max(M,c-N);
        }
        return M;
    }
};
```
['C++']