Binary Search Solution.
Sort the array by its price and then modify the items array in such a way that each item contains the maximum value that we can get within that price.\n\nfor ex
Sort the array by its price and then modify the items array in such a way that each item contains the maximum value that we can get within that price.\n\nfor example if we have items=[[2,5], [3,2], [4,4]]\nthen modified items=[[2,5], [3,5], [4,5]]\nhere the values of items[1] and items[2] is 5 because that is the maximum value we can get within price=4, price=3 and price=2.\n\nNow the items array contains the maximum value that we can get within price p. So for each query we just need to find the index of the item for which price<=queries[i].**\n\nQuestion with similar concept : https://leetcode.com/problems/two-best-non-overlapping-events/\n\n```\nvector<int> maximumBeauty(vector<vector<int>>& items, vector<int>& queries) {\n        sort(items.begin(), items.end());\n        int cur=0;\n        for(int i=0;i<items.size();i++){\n            cur=max(items[i][1], cur);\n            items[i][1]=cur;\n        }\n        vector<int>ans;\n        for(int i=0;i<queries.size();i++){\n            int x=queries[i];\n            int low=0, high=items.size()-1, mid=0, a=-1;\n            while(low<high){\n                mid=low+(high-low)/2;\n                if(items[mid][0]<=x){\n                    a=mid;\n                    low=mid+1;\n                }else{\n                    high=mid-1;\n                }\n            }\n            if(items[low][0]<=x)a=low;\n            if(a==-1)ans.push_back(0);\n            else\n            ans.push_back(items[a][1]);\n        }\n        return ans;\n    }\n```
['Sorting', 'Binary Tree', 'C++']