C++ | Binary Search
Explaining\nfor each index i binary search on the first index greater than i that have start time greater than end time of i\n\n# Complexity\nO(n * log)\n\n# Co
# Explaining\n<h3>for each index i binary search on the first index greater than i that have start time greater than end time of i</h3>\n\n# Complexity\n<h3>O(n * log)</h3>\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxTwoEvents(vector<vector<int>>& x) {\n        sort(x.begin(), x.end());\n\n        int n = x.size();\n        vector<int>suf(n + 1);\n\n        int ans = 0;\n        for(int i = n - 1; ~i ;i--)\n            suf[i] =  max(x[i][2], suf[i + 1]);\n\n        for(int i = 0; i < n ;i++){\n            int id = upper_bound(x.begin(), x.end(), vector<int>{x[i][1], (int)2e9, (int)2e9}) - x.begin();\n\n            ans=max(ans, x[i][2]);\n            if(id != n)\n                ans = max(ans, x[i][2] + suf[id]);\n        }\n        return ans;\n    }\n};\n\n```\n![hhh.png](https://assets.leetcode.com/users/images/f96694bb-97ed-4614-b21c-f026fc74bfe5_1733641265.743601.png)\n\n
['Binary Search', 'Sorting', 'C++']