C++ with single iteration. O(sizeof(n)).
\nclass Solution {\npublic:\n    long long minimumMoney(vector<vector<int>>& transactions) {\n        long long loss = 0;\n        int maxa = 0;\n        for(in
```\nclass Solution {\npublic:\n    long long minimumMoney(vector<vector<int>>& transactions) {\n        long long loss = 0;\n        int maxa = 0;\n        for(int i = 0; i < transactions.size(); ++i)\n        {\n            if(transactions[i][0] > transactions[i][1])\n            {\n                loss += transactions[i][0]-transactions[i][1];\n                maxa = max(maxa, transactions[i][1]);\n            }\n            else\n                maxa = max(maxa, transactions[i][0]);\n        }\n        return loss + (long long)maxa;\n    }\n};\n```
[]