[C++] Sort + Suffix Max + Binary Search || Very Clean Code || Detailed Explanation
We solve the problem in 3 steps:\nStep 1 - Sort the events based on starting time.\n\nStep 2 - For every event (Starting from the last event), we find the maxim
**We solve the problem in 3 steps:**\n***Step 1*** - Sort the events based on starting time.\n\n***Step 2*** - For every event (Starting from the last event), we find the maximum value we can get if we go to any event starting after that (Including the current event). \nWe store that value in a map, where, Key -> Start time and Value -> Maximum value we can get after attending any event scheduled on or after the start time (key).\n\n***Step 3***  - Now, for every event (say \'curr\'), we find the upper_bound of the end time of curr in the map (which stores the start times as keys). We can attend any event scheduled on/after that time (say \'t\'). Therefore, the current maximum possible score would be m[t] + value of curr.\n\n```\nclass Solution {\npublic:\n    int maxTwoEvents(vector<vector<int>>& events) {\n        int n = events.size();\n\t\t//Step 1\n        sort(events.begin(), events.end());\n        map<int, int> m;\n       \n\t    //Step 2\n        m[events[n-1][0]] = events[n-1][2];\n        int curr = events[n-1][2];\n        for(int i = n-2; i>=0; i--) {\n            curr = max(curr, events[i][2]);\n            m[events[i][0]] = curr;\n        }\n       \n\t   //Step 3\n        int res = 0;\n        for(int i = 0; i<n; i++) {\n            auto it = m.upper_bound(events[i][1]);\n            res = max(res, events[i][2]);\n            if(it != m.end()) {\n                res = max(res, events[i][2] + it -> second);\n            }\n        }\n        \n        return res;\n    }\n};\n````
['Binary Search', 'Sorting']