Clean C++ monotonic stack solution
Approach\nProcess num1 values in descending order. Maintain a monotonical stack of {$y$, sum} where $y$ increases as sum decreases. For each query, perform a bi
# Approach\nProcess num1 values in descending order. Maintain a monotonical stack of {$y$, sum} where $y$ increases as sum decreases. For each query, perform a binary search on the stack to find the maximum sum given a minimum $y$.\n\n# Complexity\n- Time complexity:\n$O((n+m)\\log(n) + m\\log(m))$\n\n- Space complexity:\n$O(n+m)$\n\nwhere $m$ is the number of queries\n\n# Code\nhttps://leetcode.com/submissions/detail/968598832/\n```\nclass Solution {\npublic:\n    vector<int> maximumSumQueries(vector<int>& nums1, vector<int>& nums2, vector<vector<int>>& queries) {\n        vector<pair<int,int>> data;\n        const int n = nums1.size();\n        for (int i = 0; i < n; ++i) {\n            data.push_back({nums1[i], nums2[i]});\n        }\n        sort(data.begin(), data.end(), greater<pair<int,int>>());\n        \n        vector<tuple<int,int,int>> qq;\n        const int m = queries.size();\n        for (int j = 0; j < m; ++j) {\n            auto &q = queries[j];\n            qq.push_back({q[0], q[1], j});\n        }\n        sort(qq.begin(), qq.end(), greater<tuple<int,int,int>>());\n        \n        vector<int> result(m);\n        vector<pair<int,int>> mono;\n        int i = 0;\n        for (auto [x, y, j]: qq) {\n            while (i < n && data[i].first >= x) {\n                auto [a, b] = data[i++];\n                int sum = a + b;\n                while (mono.size() && sum >= mono.back().second) {\n                    mono.pop_back();\n                }\n                if (mono.empty() || b > mono.back().first) {\n                    mono.push_back({b, sum});\n                }\n            }\n            auto it = lower_bound(mono.begin(), mono.end(), pair<int,int>{y, INT_MIN});\n            result[j] = (it == mono.end()) ? -1 : it->second;\n        }\n        return result;\n        \n    }\n};\n```
['Binary Search', 'Sorting', 'Monotonic Stack', 'C++']