Sorting Greedily || O(nLogn) solution || 0ms
```\nclass Solution {\npublic:\n    bool static cmp(vector&a,vector&b){\n        return a[1]&a,vector\&b){\n        return a[0]>b[0];\n    }\n    long long mini
```\nclass Solution {\npublic:\n    bool static cmp(vector<int>&a,vector<int>&b){\n        return a[1]<b[1];\n    }\n    bool static cmp2(vector<int>&a,vector<int>&b){\n        return a[0]>b[0];\n    }\n    long long minimumMoney(vector<vector<int>>&a) {\n        //sort(a.begin(),a.end(),cmp);\n        long long ans=0;\n        long long prv=0;\n        int n=a.size();\n        vector<vector<int>>b,c;\n        // for(auto i:a){\n        //     cout<<i[0]<<" "<<i[1]<<"\\n";\n        // }\n        for(auto i:a){\n            if(i[1]-i[0]<0){\n                b.push_back(i);\n            }else{\n                c.push_back(i);\n            }\n        }\n        sort(b.begin(),b.end(),cmp);\n        sort(c.begin(),c.end(),cmp2);\n        for(int i=0;i<b.size();i++){\n            long long cur=b[i][0];\n            long long cb=b[i][1];\n            if(prv>=cur){\n                prv=prv-cur+cb;\n            }else{\n                ans+=(cur-prv);\n                prv=cb;\n            }\n        }\n        for(int i=0;i<c.size();i++){\n            long long cur=c[i][0];\n            long long cb=c[i][1];\n            if(prv>=cur){\n                prv=prv-cur+cb;\n            }else{\n                ans+=(cur-prv);\n                prv=cb;\n            }\n        }\n        return ans;\n    }\n};
['Greedy', 'Sorting']