C++ with comments | Easy Explanation |  Map STL
\nclass Solution {\npublic:\n    int maxTwoEvents(vector<vector<int>>& e) {\n        \n        map<int,int>startTimeAndMaxi ;  \n        \n        int maximum =
```\nclass Solution {\npublic:\n    int maxTwoEvents(vector<vector<int>>& e) {\n        \n        map<int,int>startTimeAndMaxi ;  \n        \n        int maximum = 0 ; \n        int answer = 0 ; \n        \n        sort(e.begin() , e.end())  ; // Sorted acc. to StartTime\n        \n        int size = e.size()  ; \n        \n        while(size--){\n            \n            auto itr = startTimeAndMaxi.upper_bound(e[size][1])  ;  // itr points to startTime which is next greater than current Endtime (e[size][1]) --> it removes overlapping\n            \n            maximum = max(maximum, e[size][2]) ;  // assuming that curr is the only possible max value\n            \n            startTimeAndMaxi[e[size][0]] = maximum ;  // mapping curr start time with maximum value\n            \n            if(itr == startTimeAndMaxi.end()){\n                answer = max(answer , maximum)  ;  // itr not able to find the next startTime\n            }\n            else{\n                answer = max(answer , itr->second + e[size][2]) ;   // itr found next startTime . Now it will add currVal + maximum value till now\n            }\n              // answer and maximum keep getting updated\n        }\n        \n        return answer; \n        \n    }\n};\n```
['Dynamic Programming', 'C']