[C++] Binary Search and HashMap
\nclass Solution {\npublic:\n    \n    int next(vector<vector<int>>& arr, int target, int end){\n      \n        if(end==0) return -1;\n        if(target>arr[en
```\nclass Solution {\npublic:\n    \n    int next(vector<vector<int>>& arr, int target, int end){\n      \n        if(end==0) return -1;\n        if(target>arr[end-1][0]) return end-1;\n   \n        int start=0;\n \n        int ans=-1;\n        while (start<=end){\n            int mid=(start+end)/2;\n\n            if (arr[mid][0]>=target){\n                end=mid-1;\n            }\n\n            else{\n                ans=mid;\n                start=mid+1;\n            }\n        }\n        \n        return ans;\n    }\n    \n    vector<int> maximumBeauty(vector<vector<int>>& items, vector<int>& queries) {\n        \n        map<int,int>mp;\n        sort(items.begin(),items.end());\n        int mx=INT_MIN;\n        for(auto x:items){\n            mx=max(mx,x[1]);\n            mp[x[0]]=mx;\n        }\n        \n        /*\n        for(auto x:items){\n            cout<<x[0]<<" "<<x[1]<<\'\\n\';\n        }*/\n        \n        vector<int>res;\n        for(auto x:queries){\n            if(!(mp[x])){\n                \n                if(x<items[0][0]) mp[x]=0;\n                else if(x>=items[items.size()-1][0]) mp[x]=mp[items[items.size()-1][0]];\n                else {\n                    int k=next(items,x,items.size());\n                    mp[x]=mp[items[k][0]];\n                }\n                      \n            }\n            \n            res.push_back(mp[x]);\n        }\n        \n        return res;\n        \n    }\n};\n```
[]