Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Sort (x, y) tuples and queries by x-coordinate descending. Don’t forget to index queries before sorting so that you can answer them in the correct order.
Before answering a query (min_x, min_y), add all (x, y) pairs with x >= min_x to some data structure.
Use a monotone descending map to store (y, x + y) pairs. A monotone map has ascending keys and descending values. When inserting a pair (y, x + y), remove all pairs (y', x' + y') with y' < y and x' + y' <= x + y.
To find the insertion position use binary search (built-in in many languages).
When querying for max (x + y) over y >= y', use binary search to find the first pair (y, x + y) with y >= y'. It will have the maximum value of x + y because the map has monotone descending values.