Intuitive way
IntuitionApproachComplexityCode
# Intuition
    1. I took a i'th interval. Now I can take another interval iff
    the another one not overlap means eighter that interval will start
    after the current's end time or that interval will end before
    current's start time.

    2. For each interval I will get start, end, value. So
    I can keep max value for end < starttime and endtime < start
    and track the max value and add up value.

# Approach
<!-- Describe your approach to solving the problem. -->


# Complexity
    - Time complexity: O(nlogn)
    - Space complexity: O(n)

# Code
```cpp []
class Solution {
public:
    int maxTwoEvents(vector<vector<int>>& events) {
        map<int, int> st, ed;
        unordered_map<int, int> stmax, edmax;

        for(vector<int> v:events) {
            int stTime = v[0];
            int edTime = v[1];
            int value = v[2];

            st[stTime] = max(st[stTime], value);
            ed[edTime] = max(ed[edTime], value);
        }


        int maxx = 0;
        for(auto i = st.rbegin(); i != st.rend(); i++) {
            maxx = max(maxx, i -> second);
            i -> second = maxx;
        }

        maxx = 0;
        for(auto i = ed.begin(); i != ed.end(); i++) {
            maxx = max(maxx, i -> second);
            i -> second = maxx;
        }

        int ans = 0;
        for(vector<int> v:events) {
            int stTime = v[0];
            int edTime = v[1];
            int value = v[2];

            int maxx = 0;
            auto it = st.upper_bound(edTime);
            if(it != st.end()) {
                maxx = it -> second;
            }
            it = ed.lower_bound(stTime);
            if(it != ed.begin()) {
                --it;
                maxx = max(maxx, it -> second);
            }

            ans = max(ans, value+maxx);
        }

        return ans;
    }
};
```
['C++']