C++ | No segment tree | Sort | Data Structure
Approach\nFor every integer in v1, only the maxmimum sum will be considered, e.g. v1 = [5, 5], v2 = [20, 40], we will only keep {5, 40}. Then, sort queries by f
# Approach\nFor every integer in v1, only the maxmimum sum will be considered, e.g. ```v1 = [5, 5]```, ```v2 = [20, 40]```, we will only keep ```{5, 40}```. Then, sort queries by first value desc. Iterate through queries, update set of available pairs ```s```, and get answer from the back of available set.\n\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> maximumSumQueries(vector<int>& v1, vector<int>& v2, vector<vector<int>>& qss) {\n        int n = v1.size(), m = qss.size();\n\n        // maximum sum for every interger in v1\n        map<int, int> mp;\n        for (int i = 0; i < n; i++) {\n            mp[v1[i]] = max(mp[v1[i]], v1[i] + v2[i]);\n        }\n\n\n        vector<vector<int>> qs(m);\n        for (int i = 0; i < m; i++) {\n            qs[i] = {qss[i][0], qss[i][1], i};\n        }\n        sort(qs.begin(), qs.end(), greater());\n\n        \n        vector<int> ans(m, -1);\n        auto it = mp.rbegin();\n        set<vector<int>> s;\n\n        for (auto &q : qs) {\n            int a = q[0], b = q[1], idx = q[2];\n\n            // update available set {{sum, v2[i]}}\n            while (a <= it->first && it != mp.rend()) {\n                s.insert({it->second, it->second - it->first});\n                it++;\n            }\n\n            // look for answer, from the greatest sum\n            for (auto it2 = s.rbegin(); it2 != s.rend(); it2++) {\n                if ((*it2)[1] >= b) {\n                    ans[idx] = (*it2)[0];\n                    break;\n                }\n            }\n        }\n        \n        return ans;\n    }\n};\n```
['C++']