Greedy Approach
Intuition\nThe best way to choose an interval works as follows:\n\n-> choose any interval\n-> sum the value of chose events with the maximum value of events whi
# Intuition\nThe best way to choose an interval works as follows:\n\n-> choose any interval\n-> sum the value of chose events with the maximum value of events which ended before it \n-> Now the maximum of the value we obtained in the above step is the answer\n\n# Complexity\n- Time complexity:\nO(nlog(n))\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\npublic:\n    int maxTwoEvents(vector<vector<int>>& events) {\n        vector<pair<int, int>> start, end;\n\n        for(const auto &it: events) {\n            start.push_back({it[0], it[2]});\n            end.push_back({it[1], it[2]});\n        }\n\n        sort(start.begin(), start.end());\n        sort(end.begin(), end.end());\n\n        int si = 0, ei = 0, mxe = 0, ans = 0;\n\n        while(si < events.size()) {\n            while(end[ei].first < start[si].first) {\n                mxe = max(mxe, end[ei].second);\n                ei++;\n            }\n\n            ans = max(ans, start[si].second + mxe);\n\n            si++;\n        }\n\n        return ans;\n    }\n};\n```\n\nI\'m still learning the best way to share my learnings and approach. Please let me know if there is something I can improve\n
['Greedy', 'C++']