Two Cases
Based on the lee215 solution.\n\nWe need to compute how much money we must spend, which is sum(cost_i - cachback_i).\n\nNote that we do not care about the profi
Based on the [lee215](https://leetcode.com/problems/minimum-money-required-before-transactions/discuss/2588034/JavaC%2B%2BPython-Easy-and-Coincise) solution.\n\nWe need to compute how much money we must `spend`, which is `sum(cost_i - cachback_i)`.\n\nNote that we do not care about the profit - as we can execute those transactions at the very end. We just assume that we need to spend zero on those transactions.\n\nThere is also an overhead on top of what we need to `spend`. We have two cases here:\n- For `negative` transactions, the cashback from the very last transaction cannot be utilized, so we need to add it to `spend`. \n\t- We track the maximum `cashback` for those transactions.\n- For `neutral` transactions, we need an upfront cost to make the first transaction.\n\t- We track the maximum `cost` for such transactions.\n\nIn the end, we need at least `spend` + `max(cachback, cost)` money to execute all transactions in any order.\n\n**C++**\n```cpp\nlong long minimumMoney(vector<vector<int>>& ts) {\n    long long spend = 0, cashback = 0, cost = 0;\n    for (auto &t : ts) {\n        if (t[0] > t[1]) {\n            spend += t[0] - t[1];\n            cashback = max(cashback, (long long)t[1]);\n        } else\n            cost = max(cost, (long long)t[0]);\n    }\n    return spend + max(cashback, cost);\n}  \n```
['C']