Binary Search
\n#define ll long long \nclass Solution {\npublic:\n    \n    bool check(ll m, vector<vector<int>>&transactions)\n    {\n        ll d = 0;\n        for(int i=0;
```\n#define ll long long \nclass Solution {\npublic:\n    \n    bool check(ll m, vector<vector<int>>&transactions)\n    {\n        ll d = 0;\n        for(int i=0; i<transactions.size(); i++)\n        {\n            if(transactions[i][0] >= transactions[i][1])\n                d += transactions[i][0] - transactions[i][1];\n        }\n        for(int i = 0; i<transactions.size(); i++)\n        {\n            if(transactions[i][0] >= transactions[i][1])\n            {\n                ll d1 = transactions[i][0] - transactions[i][1];\n                if(m - (d - d1) < transactions[i][0])\n                    return false;\n            }\n            else\n            {\n                if(m - d < transactions[i][0])\n                    return false;\n            }\n        }\n        return true;\n    }\n    \n    long long minimumMoney(vector<vector<int>>& transactions) {\n        ll lo = 0, hi = 1e18, ans = 1e18;\n        while(lo <= hi)\n        {\n            ll mid = lo + (hi - lo)/2;\n            if(check(mid, transactions))\n            {\n                ans = mid;\n                hi = mid-1;\n            }\n            else\n                lo = mid+1;\n        }\n        return ans;\n    }\n};\n```
[]