python 3 | sorting + monotonic stack + binary search
Complexity\n- Time complexity:\n$O((n + m)\log{n} + m\log{m})$\n\n- Space complexity:\n$O(n + m)$\n\n# Code\n\nclass Solution:\n    def maximumSumQueries(self, 
# Complexity\n- Time complexity:\n$O((n + m)\\log{n} + m\\log{m})$\n\n- Space complexity:\n$O(n + m)$\n\n# Code\n```\nclass Solution:\n    def maximumSumQueries(self, nums1: List[int], nums2: List[int], queries: List[List[int]]) -> List[int]:\n        n = len(nums1)\n        numsOrder = sorted(range(n), key=lambda j: -nums1[j])\n        m = len(queries)\n        queriesOrder = sorted(range(m), key=lambda i: -queries[i][0])\n        answer = [-1] * m\n        stack = []\n        k = 0\n        for i in queriesOrder:\n            x, y = queries[i]\n            while k < n and nums1[j := numsOrder[k]] >= x:\n                k += 1\n                if stack and stack[-1][1] >= nums2[j]:\n                    continue\n                total = nums1[j] + nums2[j]\n                while stack and stack[-1][0] + stack[-1][1] <= total:\n                    stack.pop()\n                stack.append((nums1[j], nums2[j]))\n            s = bisect_left(stack, y, key=lambda item: item[1])\n            if s < len(stack):\n                answer[i] = stack[s][0] + stack[s][1]\n        return answer\n```
['Binary Search', 'Sorting', 'Monotonic Stack', 'Python', 'Python3']