C++ | with explanation | Concise | DP
Idea:-\n1. Sort the events according to startTime and iterate from last.\n2. maxi will store maximum value from events whose startTime>= current event\'s startT
**Idea:-**\n1. Sort the events according to ```startTime``` and iterate from last.\n2. ```maxi``` will store maximum value from events whose ```startTime>= current event\'s startTime```.\n3. So when we are iterating over events we check the map to find an event whose ```startTime``` is greater than current event\'s endTime.\n4. Update the ```maxi and ans``` accordingly.\n\n**Similar problem:-** [Maximum Profit in Job Scheduling](https://leetcode.com/problems/maximum-profit-in-job-scheduling/)\n**Time Complexity :-** O(nlog(n)).\n```\nclass Solution {\npublic:\n    int maxTwoEvents(vector<vector<int>>& e) {\n        int size=e.size(),ans=0,maxi=0;\n        sort(e.begin(),e.end());\n        map<int,int>mp;\n        while(size--){\n            auto it=mp.upper_bound(e[size][1]);\n            maxi=max(maxi,e[size][2]);\n              mp[e[size][0]]=maxi;\n            if(it==mp.end())\n                ans=max(ans,maxi);\n            else\n                ans=max(ans,e[size][2]+it->second);\n        }\n        return ans;\n    }\n};\n```\nDo **UPVOTE** if it helps :)
['Dynamic Programming', 'C']