Segment Tree, Max Range Query
\n# Code\ncpp []\nclass segmentTree {\n    vector<int> tree;\n    int n;\npublic:\n    segmentTree(int n) {\n        this->n = n;\n        tree = vector<int>(4 
\n# Code\n```cpp []\nclass segmentTree {\n    vector<int> tree;\n    int n;\npublic:\n    segmentTree(int n) {\n        this->n = n;\n        tree = vector<int>(4 * n, -1);\n    }\n\n    void update(int pos, int val, int l = 0, int r = -1, int i = 0) {\n        if (r == -1) r += n;\n        if (l == r) {\n            tree[i] = val;\n            return;\n        }\n        int m = (l + r) >> 1;\n        if (pos <= m) update(pos, val, l, m, 2 * i + 1);\n        else update(pos, val, m + 1, r, 2 * i + 2);\n\n        tree[i] = max(tree[2 * i + 1], tree[2 * i + 2]);\n    }\n\n    int query(int x, int y, int l = 0, int r = -1, int i = 0) {\n        if (r == -1) r += n;\n\n        if (r < x or l > y) return -1;\n        if (l >= x and r <= y) return tree[i];\n\n        int m = (l + r) >> 1;\n        return max(\n            query(x, y, l, m, 2 * i + 1),\n            query(x, y, m + 1, r, 2 * i + 2)\n        );\n    }\n};\n\nclass Solution {\n    vector<int> ans;\npublic:\n    vector<int> maximumSumQueries(vector<int>& nums1, vector<int>& nums2, vector<vector<int>>& queries) {\n        int m = queries.size();\n        int n = nums1.size();\n        ans = vector<int>(m, -1);\n\n        vector<pair<int, int>> v, b_pairs;  \n        for (int i = 0; i < n; i++) {\n            v.push_back({nums1[i], nums2[i]});\n        }\n        sort(v.begin(), v.end(), [&](pair<int, int> a, pair<int, int> b) {\n            return a.first > b.first;\n        });\n\n        for (int i = 0; i < n; i++) {\n            b_pairs.push_back({v[i].second, i});\n        }\n        sort(b_pairs.begin(), b_pairs.end());\n\n        map<int, int> position;\n\n        for (int i = 0; i < n; i++) {\n            position[b_pairs[i].second] = i;\n        }\n\n        for(int i = 0; i < m; i++) queries[i].push_back(i);\n\n        sort(queries.begin(), queries.end(), [&](vector<int>& a, vector<int>& b) {\n            return a[0] > b[0];\n        });\n\n        segmentTree tree(n);\n\n        int i = 0;\n        for (auto& q : queries) {\n            int a = q[0], b = q[1], index = q[2];\n\n\n            while (i < n and v[i].first >= a) {\n                tree.update(position[i], v[i].first + v[i].second);\n                i++;\n            }\n\n\n            auto lb = lower_bound(b_pairs.begin(), b_pairs.end(), make_pair(b, -1)) - b_pairs.begin();\n\n            if (lb == n) {\n                ans[index] = -1;\n            } else {\n                ans[index] = tree.query(lb, n - 1);\n            }\n        }\n        return ans;\n    }\n};\n\n```
['C++']