Easy Explanation for Binary Search || C++
Intuition\nFind the maximum Value of two non-overlapping events\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. We know that if 
# Intuition\nFind the **maximum Value** of two non-overlapping events\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. We know that if `event i` end before `event j`, then every `event n` that ended before `event i-1` is also ended.\n2. For that we sort the `events` on the bases of there `endTime`.\n3. Since `event i` is already ended and is not overlapping with `event j` we take the maximum `value` from the `events` happened till the starting of `event j`.\n4. For that we made a array `dp` storing the maxValue that appered till index `i`\n5. Now we need to check one by one from index `0` to index `i-1` if there exist an event thats not overlapping with index `i` and to do it faster we do BinarySearch\n6. Changing the maxElement if we found any\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n.logn)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxTwoEvents(vector<vector<int>>& events) {\n        sort(events.begin(),events.end(), [](const vector<int>& a,const vector<int>& b){\n            return a[1]<b[1];\n        }); // Increasing endTime order\n\n        int maxElement = 0;\n        vector<int> dp(events.size(),0);\n        for(int i=0;i<events.size();i++){\n            maxSingle = max(maxSingle,events[i][2]);\n            dp[i]=maxSingle;\n        }\n\nmaxElement = 0;\n\n        for(int i=0;i<events.size();i++){\n            int left = 0;\n            int right = i-1;\n\n            int sum = 0;\n            while(left<=right){\n                int mid=(right+left)/2;\n                if(events[mid][1]<events[i][0]){\n                    sum = max(sum,dp[mid]);\n                    left=mid+1;\n                }else{ right=mid-1;}\n            }\n            sum+=events[i][2];\n            maxElement = max(maxElement,sum);\n        }\n        return maxElement;\n    }\n};\n```
['Binary Search', 'C++']