My Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nstruct Pair {\n  int x;\n  int y;\n};\n\nstruct IndexAndQuery {\n  int index;  // the index in `queries`\n  int minX;   // queries[i] := (minX, minY)\n  int minY;\n};\n\nclass Solution {\n public:\n  vector<int> maximumSumQueries(vector<int>& nums1, vector<int>& nums2,\n                                vector<vector<int>>& queries) {\n    const vector<Pair> pairs = getPairs(nums1, nums2);\n    const vector<IndexAndQuery> indexAndQueries = getIndexAndQueries(queries);\n    vector<int> ans(queries.size());\n    vector<pair<int, int>> stack;  // [(y, x + y)]\n\n    int i = 0;\n    for (const auto& [index, minX, minY] : indexAndQueries) {\n      while (i < pairs.size() && pairs[i].x >= minX) {\n        const auto [x, y] = pairs[i++];\n        // x + y is a better candidate. Given that x is decreasing, the\n        // condition "x + y >= stack.back().second" suggests that y is\n        // relatively larger, thereby making it a better candidate.\n        while (!stack.empty() && x + y >= stack.back().second)\n          stack.pop_back();\n        if (stack.empty() || y > stack.back().first)\n          stack.emplace_back(y, x + y);\n      }\n      const auto it = lower_bound(stack.begin(), stack.end(),\n                                  pair<int, int>{minY, INT_MIN});\n      ans[index] = it == stack.end() ? -1 : it->second;\n    }\n\n    return ans;\n  }\n\n private:\n  vector<Pair> getPairs(const vector<int>& nums1, const vector<int>& nums2) {\n    vector<Pair> pairs;\n    for (int i = 0; i < nums1.size(); ++i)\n      pairs.push_back({nums1[i], nums2[i]});\n    sort(pairs.begin(), pairs.end(),\n         [](const Pair& a, const Pair& b) { return a.x > b.x; });\n    return pairs;\n  }\n\n  vector<IndexAndQuery> getIndexAndQueries(const vector<vector<int>>& queries) {\n    vector<IndexAndQuery> indexAndQueries;\n    for (int i = 0; i < queries.size(); ++i)\n      indexAndQueries.push_back(IndexAndQuery{\n          .index = i,\n          .minX = queries[i][0],\n          .minY = queries[i][1],\n      });\n    sort(indexAndQueries.begin(), indexAndQueries.end(),\n         [](const IndexAndQuery& a, const IndexAndQuery& b) {\n      return a.minX > b.minX;\n    });\n    return indexAndQueries;\n  }\n};\n\n```
['C++']