Greedy O(n) solution (No sorting)
Idea:: The worst thing that can happen before each transaction is doing all money loosing transaction before the current one.\nThe money loosing transaction is 
**Idea**:: The worst thing that can happen before each transaction is doing all money loosing transaction before the current one.\nThe money loosing transaction is transaction in which cashback is less than cost\n\n```\nclass Solution {\npublic:\n    long long minimumMoney(vector<vector<int>>& t) \n    {\n \n        \n        long long money=0;\n        long long ans =0;\n        vector<int>v;\n        \n        for(int i=0;i<t.size();i++)\n        {\n            ans = max(ans,1LL*t[i][0]);\n         \n        }\n        \n        int n = t.size();\n        for(int i=0;i<n;i++)\n        {\n            \n           if((t[i][1]-t[i][0])<=0)   // A money loosing transaction\n           {\n               money+=t[i][1]-t[i][0];\n           }\n            \n            \n        }\n\t\tans = max(ans,abs(money));\n        // money stores the money which I have to loose ultimatelty;\n\t\t\n\t\t\n        for(int i=0;i<n;i++)\n        {\n\t\t   \n\t\t    // the worst thing that can happen before ith trancation is doing all money loosing transactions \n\t\t\t//  before ith one\n\t\t\t\n            if((t[i][1]-t[i][0])<=0)  // if ith transaction is money loosing\n            {\n                money-=t[i][1]-t[i][0];  // remove contribution of ith transaction which is added in money \n\t\t\t\t                                   // above\n            }\n            if((money-t[i][0])<0)\n            {\n                ans = max(ans,abs(money-t[i][0]));  // money required is max of ans and (cost of ith transaction) + loosing money \n            } \n          \n             if((t[i][1]-t[i][0])<=0) \n            {\n                money+=t[i][1]-t[i][0]; // just undo the changes made for ith transaction\n            }\n\n        }\n        \n        return ans;\n        \n    }\n};\n```
['Greedy', 'C++']