C++ greedy O(N)
```\n    long long minimumMoney(vector>& transactions) {\n        // res - c1 + cb1 - c2 + cb2 +... -cn >=0\n        // res >= (c1+c2+...+cn) - (cb1-cb2-...cbn)
```\n    long long minimumMoney(vector<vector<int>>& transactions) {\n        // res - c1 + cb1 - c2 + cb2 +... -cn >=0\n        // res >= (c1+c2+...+cn) - (cb1-cb2-...cbn) + cbn\n        long long maxDelta, maxCostPos = 0, maxCbNag = 0;\n        for(auto& v:transactions){\n            if (v[0] < v[1])\n                maxCostPos = max<int>(maxCostPos, v[0]);\n            else {\n                maxCbNag = max<int>(maxCbNag, v[1]);\n                maxDelta += v[0] - v[1];\n            }\n        }\n        return maxDelta + max(maxCostPos , maxCbNag);\n    }
[]