Badiya solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\n#define ll long long\nclass Solution {\npublic:\n\n    static bool comp(vector<int> &a, vector<int> &b) {\n        if(a[1] == b[1]) {\n            return a[0] < b[0];\n        }\n        return a[1] < b[1];\n    }\n    \n    static bool comp2(vector<int> &a, vector<int> &b) {\n        if(a[0] == b[0]) {\n            return a[1] < b[1];\n        }\n        return a[0] > b[0];\n    }\n\n    long long minimumMoney(vector<vector<int>>& t) {\n        vector<vector<int>> a, b;\n        for(int i = 0 ; i < t.size() ; i++) {\n            vector<int> v;\n            v.push_back(t[i][0]);\n            v.push_back(t[i][1]);\n            if(t[i][0] >= t[i][1]) {\n                a.push_back(v);\n            }\n            else{\n                b.push_back(v);\n            }\n        }\n        sort(a.begin(), a.end(), comp);\n        sort(b.begin(), b.end(), comp2);\n        ll ans = 0;\n        ll k = 0;\n        for(int i = 0 ; i < a.size() ; i++) {\n            if(a[i][0] > ans) {\n                k += a[i][0] - ans;\n                ans += a[i][0] - ans;\n            }\n            ans = ans - a[i][0] + a[i][1];\n        }\n        for(int i = 0 ; i < b.size() ; i++) {\n            if(b[i][0] > ans) {\n                k += b[i][0] - ans;\n                ans += b[i][0] - ans;\n            }\n            ans = ans - b[i][0] + b[i][1];\n        }\n        return k;\n    }\n};\n```
['Array', 'Greedy', 'Sorting', 'C++']