Easy C++ O(n)
\nclass Solution {\npublic:\n    long long minimumMoney(vector<vector<int>>& transactions) {\n        \n        long ret = 0;\n        int maxcost = INT_MIN;\n 
```\nclass Solution {\npublic:\n    long long minimumMoney(vector<vector<int>>& transactions) {\n        \n        long ret = 0;\n        int maxcost = INT_MIN;\n        int maxback = INT_MIN;\n        for (auto & t : transactions) {\n            int delta = t[1] - t[0];\n            if (delta < 0) {\n                ret += delta;\n                maxback = max(maxback, t[1]);\n            }\n            else {\n                maxcost = max(maxcost, t[0]);\n            }\n        }\n        return -min(ret - maxcost, ret - maxback);\n    }\n};\n```
[]