Java O(nLogn) + O(qLogn) | Sort + Binary Search
\nclass Solution {\n    public int[] maximumBeauty(int[][] items, int[] q) {\n        \n        Arrays.sort(items,(a,b)->a[0]-b[0]); // sort on the basis of pri
```\nclass Solution {\n    public int[] maximumBeauty(int[][] items, int[] q) {\n        \n        Arrays.sort(items,(a,b)->a[0]-b[0]); // sort on the basis of prices.\n        \n        for(int i = 1; i < items.length; i++){\n            items[i][1] = Math.max( items[i][1], items[i-1][1] ); // ith item will store max beauty till now.\n        }\n        \n        int n = q.length;\n        int ans[] = new int[n];\n        \n        for(int i = 0; i < n; i++){\n            \n            int s = 0, e = items.length - 1;\n            \n            while(s <= e){  // perform binary search to find the last price <= queries[i].\n                int mid = s + (e - s) / 2;\n                \n                if(items[mid][0] <= q[i]) {\n                    s = mid + 1;\n                    ans[i] = Math.max( ans[i], items[mid][1] );        // update ans[i] for max value.\n                }else{\n                    e = mid - 1;\n                }\n            \n            }\n            \n        }\n    \n        return ans;\n    \n    }\n}\n```
[]