C++| 97% faster | 99.26% memory | Binary Search | Explained
Steps are explained in comments (If any doubt or any modification please comment)\n\n\nclass Solution {\npublic:\n    int maxTwoEvents(vector<vector<int>>& even
**Steps are explained in comments** (If any doubt or any modification please comment)\n\n```\nclass Solution {\npublic:\n    int maxTwoEvents(vector<vector<int>>& events) {\n        ios::sync_with_stdio(false);cin.tie(NULL);\n        \n        //sort the events according to their start time\n        sort(events.begin(),events.end());\n        \n        int n=events.size();\n        //store the maxvalue till that element from right.\n        vector<int>R(n,events[n-1][2]);\n        for(int i=n-2;i>=0;i--){\n            R[i]=max(R[i+1],events[i][2]);\n        }\n        \n        int ans=0;\n        for(int i=0;i<n;i++){\n            int l=i+1, r=n-1;\n            int idx = -1;\n            //find first index whose start-time is greater than current event\'s end-time\n            while(l <= r){\n                int m=(l+r)/2;\n                if(events[m][0]>events[i][1]){\n                    idx=m;\n                    r=m-1;\n                }\n                else{\n                    l=m+1;\n                }\n            }\n            if(idx!=-1){\n                ans=max(ans,R[idx]+events[i][2]);\n            }\n           \n            \n        }\n        //check if there is any single event whose value is greater than the sum of two event\'s value.\n        return max(ans,R[0]);\n    }\n};\n\n/*\n * Time Complexity - O(nlogn)\n * Space Complexity - O(n)\n * \n*/\n```\n**Do Upvote if you like the solution**
['Binary Tree']