Easy and Simple explanation with proper comments , O(N)
\nclass Solution {\npublic:\n    // Finding the worst sequence which will lead us to the maximum.\n    long long minimumMoney(vector<vector<int>>& vp) {\n      
```\nclass Solution {\npublic:\n    // Finding the worst sequence which will lead us to the maximum.\n    long long minimumMoney(vector<vector<int>>& vp) {\n        int n=vp.size();\n        long long y=0,z=0;\n        vector<pair<int,int>>v; // All the transactions which will lead us to the maximum money required.\n        for(int i=0;i<n;i++){\n            // transactions which needs more money and gives less cashback.\n            if(vp[i][0]-vp[i][1]>0){\n                v.push_back({vp[i][0],vp[i][1]});\n                y+=vp[i][0]-vp[i][1];\n                \n            }\n            // transactions which needs less money and gives more cashback in return.\n            else{\n                // Storing the maximum cost which a transaction needs.\n                // This transaction could be the last transaction where the maximum will reach midway of the transaction.\n                z=max(z,(long long)vp[i][0]);\n            }\n        }\n        // 1st case: Maximum being all the transactions + the last we recieved from z.\n        long long ans=max(ans,y+z);\n        for(int i=0;i<v.size();i++){\n            // 2nd case: If ith transactio is the last transaction where we reach the maximum.\n            ans=max(ans,y+v[i].second);\n        }\n        return ans;\n    }\n};\n```
['Greedy', 'C']