Binary Search with Special Sort || 77.90% Faster || C++ || Simple || Short || Clean
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```\nclass Solution {\npublic:\n    #define ll long long\n\n    static bool cmp1(vector<int>&v1,vector<int>&v2){\n        if(v1[1]==v2[1]){\n            return v1[0]>v2[0];\n        }\n        return v1[1]<v2[1];\n    }\n\n    static bool cmp2(vector<int>&v1,vector<int>&v2){\n        if(v1[0]==v2[0]){\n            return v1[1]<v2[1]; \n        }\n        return v1[0]>v2[0];\n    }\n\n    bool check(vector<vector<int>>&cost,vector<vector<int>>&cashback,ll same,ll mid){\n        ll current=mid,n=cost.size(),m=cashback.size();\n        for(ll i=0;i<n;i++){\n            if(current<cost[i][0]){\n                return false;\n            }\n            current=(current-cost[i][0]+cost[i][1]);\n        }\n        if(current<same){\n            return false;\n        }\n        for(ll i=0;i<m;i++){\n            if(current<cashback[i][0]){\n                return false;\n            }\n            current=(current-cashback[i][0]+cashback[i][1]);\n        }\n        return true;\n    }\n\n    long long minimumMoney(vector<vector<int>>& transactions) {\n        ll n=transactions.size(),same=INT_MIN;\n        vector<vector<int>>cost,cashback;\n        for(auto &x:transactions){\n            if(x[1]<x[0]){\n                cost.push_back(x);\n            }\n            else if(x[1]>x[0]){\n                cashback.push_back(x);\n            }\n            else{\n                same=max(same,(ll)x[1]);\n            }\n        }\n        sort(cost.begin(),cost.end(),cmp1);\n        sort(cashback.begin(),cashback.end(),cmp2);\n        ll low=0,high=1e17,answer,mid;\n        while(low<=high){\n            mid=(low+high)>>1;\n            if(check(cost,cashback,same,mid)){\n                answer=mid;\n                high=mid-1;\n            }\n            else{\n                low=mid+1;\n            }\n        }\n        return answer;\n    }\n};\n```
['C++']