[C++] Sort for the worst case and perform Binary Search
\tclass Solution {\n\tpublic:\n\t\tlong long minimumMoney(vector>& a) {\n\t\t\tsort(a.begin(),a.end(),&{\n\t\t\t\tint trial1=min(-x[0],-x[0]+x[1]-y[0]);\n\t\t\t
\tclass Solution {\n\tpublic:\n\t\tlong long minimumMoney(vector<vector<int>>& a) {\n\t\t\tsort(a.begin(),a.end(),[&](vector<int>& x,vector<int>& y){\n\t\t\t\tint trial1=min(-x[0],-x[0]+x[1]-y[0]);\n\t\t\t\tint trial2=min(-y[0],-y[0]+y[1]-x[0]);\n\t\t\t\tif(trial1<trial2) return true;\n\t\t\t\telse if(trial1>trial2) return false;\n\t\t\t\treturn x[0]>y[0];\n\t\t\t});\n\t\t\tlong long l=0,r=1e16;\n\t\t\twhile(l<r) {\n\t\t\t\tlong long m=(l+r)/2;\n\t\t\t\tlong long x=m;\n\t\t\t\tfor(int i=0;i<a.size();i++){\n\t\t\t\t\tx=x-a[i][0];\n\t\t\t\t\tif(x<0) break;\n\t\t\t\t\tx+=a[i][1];\n\t\t\t\t}\n\t\t\t\tif(x<0) l=m+1;\n\t\t\t\telse r=m;\n\t\t\t}\n\t\t\treturn r;\n\t\t}\n\t};
['Binary Search', 'C', 'Sorting']