Two solutions: Binary search and Sorting
Binary search: time $O((M+N)\u22C5logM)$\n\nclass Solution:\n    def maximumBeauty(self, items: List[List[int]], queries: List[int]) -> List[int]:\n        item
1. Binary search: time $O((M+N)\u22C5logM)$\n```\nclass Solution:\n    def maximumBeauty(self, items: List[List[int]], queries: List[int]) -> List[int]:\n        items.sort(key = itemgetter(0))\n        max_beauty = [*accumulate(map(itemgetter(1), items), max, initial = 0)]\n        return [max_beauty[bisect_right(items, q, key = itemgetter(0))] for q in queries]\n```\n> More readable\n```\nclass Solution:\n    def maximumBeauty(self, items: List[List[int]], queries: List[int]) -> List[int]:\n        items.sort(key = itemgetter(0))\n        max_beauty, curr_max_beauty = [0], 0\n        for price, beauty in items:\n            curr_max_beauty = max(curr_max_beauty, beauty)\n            max_beauty.append(curr_max_beauty)\n        ans = []\n        for q in queries:\n            i = bisect_right(items, q, key = itemgetter(0))\n            ans.append(max_beauty[i])\n        return ans\n```\n2. Sorting: time $O(M\u22C5logM+N\u22C5logN)$\n```\nclass Solution:\n    def maximumBeauty(self, items: List[List[int]], queries: List[int]) -> List[int]:\n        items.sort(key = lambda n: -n[0])\n        ans, max_beauty = [0] * len(queries), 0\n        for i in sorted(range(len(queries)), key = lambda i: queries[i]):\n            while items and items[-1][0] <= queries[i]:\n                max_beauty = max(max_beauty, items.pop()[1])\n            ans[i] = max_beauty\n        return ans\n```
['Binary Search', 'Sorting', 'Python3']