2736. Maximum Sum Queries
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def maximumSumQueries(self, nums1: List[int], nums2: List[int], queries: List[List[int]]) -> List[int]:
        combined_values = sorted(zip(nums1, nums2))
        indexed_queries = [(limit_x, limit_y, idx) for idx, (limit_x, limit_y) in enumerate(queries)]
        indexed_queries.sort(key=lambda q: -q[0])
        output = [-1] * len(queries)
        valid_choices = []

        for limit_x, limit_y, query_idx in indexed_queries:
            while combined_values and combined_values[-1][0] >= limit_x:
                value_x, value_y = combined_values.pop()
                combined_sum = value_x + value_y
                while valid_choices and valid_choices[-1][1] <= combined_sum:
                    valid_choices.pop()
                if not valid_choices or valid_choices[-1][0] < value_y:
                    valid_choices.append((value_y, combined_sum))
            position = bisect_left(valid_choices, (limit_y,))
            if position < len(valid_choices):
                output[query_idx] = valid_choices[position][1]

        return output

```
['Python3']