C++ Binary Search with Comparator
This code is for those who tried to apply binary search and failed because of comparator :( \n\nBasically in this comparator, we are just checking whether A -> 
This code is for those who tried to apply binary search and failed because of comparator :( \n\nBasically in this comparator, we are just checking whether A -> B gives more negative money or B -> A gives more negative money.\n\n```\nbool compare1(vector<int>&A, vector<int>&B)\n{\n    int opt1 = min(-A[0], -A[0] + A[1] -B[0]) ;\n    int opt2 = min(-B[0], -B[0]+B[1]-A[0]) ;\n    \n    if(opt1 < opt2) return true ;\n    if(opt1 > opt2) return false ;\n    \n    return A[0] > B[0] ;\n}\n    \n\nclass Solution {\npublic:\n    \n    bool canSolve(vector<vector<int>>&A, long long mid)\n    {        \n        for(int i=0; i<A.size(); i++)\n        {\n            if(mid < A[i][0]) return false ;\n            \n            mid = mid - (long)A[i][0] + (long)A[i][1] ; \n        }\n        \n        return true;\n    }\n    \n    \n\n    long long Solve(vector<vector<int>>&A)\n    {\n        long long start = 0 , end = LONG_MAX ;\n        \n        while(start < end)\n        {\n            if(end-start==1) break; \n            \n            long long mid = start + (end-start)/2 ;\n            \n            if(canSolve(A,mid)) {\n                end = mid ;\n            }\n            else{\n                start = mid;\n            }\n        }\n        \n        if(canSolve(A,start)) return start ;\n        \n        return end;         \n    }\n    \n    long long minimumMoney(vector<vector<int>>& A) {\n     \n        long long Ans = -1e9 ;        \n        sort(A.begin(),A.end(), compare1) ; \n        Ans = max(Ans,Solve(A)) ;\n        return Ans ;\n    }\n};\n```
['Binary Search']