Short Python sorting + binary search
Idea is to sort queries by x-value and also process nums by x-value.\nKeep track of largest y values seen so far in a queue and binary search for result.\n\nTim
Idea is to sort queries by x-value and also process nums by x-value.\nKeep track of largest y values seen so far in a queue and binary search for result.\n\nTime: O(nlogn+qlogq+qlogn) (i think)\n\n```python\nclass Solution:\n    def maximumSumQueries(self, nums1: List[int], nums2: List[int], queries: List[List[int]]) -> List[int]:\n        x = sorted([(a,b) for a,b in zip(nums1,nums2)], reverse=True)\n        q = sorted([(a,b,i) for i,(a,b) in enumerate(queries)], reverse=True)\n        i, maxy = 0, 0\n        res = defaultdict(int)\n        d = []\n        for a,b,j in q:\n            while i < len(x) and x[i][0] >= a:\n                if x[i][1] > maxy:\n                    maxy = x[i][1]\n                    while d and d[-1][1] < x[i][0]+x[i][1]:\n                        d.pop()\n                    d.append((maxy, x[i][0]+x[i][1]))\n                i += 1\n            try:\n                res[j] = d[bisect_left(d, (b, 0))][1]\n            except:\n                res[j] = -1\n        return [res[i] for i in range(len(q))]
['Binary Search', 'Sorting', 'Python', 'Python3']