C++ || Binary search
\n\npublic:\n    static bool cmp(vector&v1,vector&v2)\n    {\n        return v1[1]<v2[1];\n    }\n    long long maxTaxiEarnings(int nn, vector>& rides) {\n     
```\n\n```public:\n    static bool cmp(vector<int>&v1,vector<int>&v2)\n    {\n        return v1[1]<v2[1];\n    }\n    long long maxTaxiEarnings(int nn, vector<vector<int>>& rides) {\n        vector<vector<int>>v;\n        int n=rides.size();\n        for(int i=0;i<rides.size();i++)\n        {\n            int x=rides[i][1]-rides[i][0]+rides[i][2];\n            v.push_back({rides[i][0],rides[i][1],x});\n        }\n        sort(v.begin(),v.end(),cmp);\n        vector<long long int>dp(n);\n        dp[0]=v[0][2];\n        for(int i=1;i<n;i++)\n        {\n            int idx=-1;\n            int l=0;\n            int r=i;\n            while(l<=r)\n            {\n                int mid=(l+r)/2;\n                if(v[mid][1]<=v[i][0])\n                {\n                    idx=mid;\n                    l=mid+1;\n                }\n                else\n                {\n                    r=mid-1;\n                }\n            }\n            if(idx==-1)\n            {\n                dp[i]=max(dp[i-1],(long long)v[i][2]);\n            }\n            else\n            {\n                dp[i]=max(dp[i-1],dp[idx]+(long long)v[i][2]);\n            }\n        }\n        return dp[n-1];\n    }\n};
['Sorting', 'Binary Tree']