Simple map 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$$O((n + q) * log(n))$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n# Code\n```\nclass Solution {\npublic:\n    vector<int> maximumSumQueries(vector<int>& a, vector<int>& b, vector<vector<int>>& q) {\n        int n = a.size(), m = q.size();\n        #define ff first\n        #define ss second\n        map<int, int> T;\n        T[1E9 + 5] = -1;\n        auto upd = [&](int x, int c){\n\t        auto it = T.lower_bound(x);\n            if(it -> ss >= c) return;\n            while(it != T.begin()){\n                auto prev = it;\n                prev--;\n                if(prev -> ss < c) T.erase(prev -> ff);\n                else break;\n            }\n            T[x] = c;\n        };\n        vector<pair<int,int>> A(1, {-1, 0});\n        for(int i = 0; i < n; i++) A.push_back({a[i], i});\n        sort(A.begin(), A.end());\n        vector<int> ans(m);\n        vector<pair<int,int>> qr;\n        for(int i = 0; i < m; i++) qr.push_back({q[i][0], i});\n        sort(qr.begin(), qr.end());\n        for(int i = n; i >= 0; i--){\n            while(!qr.empty() && qr.back().ff > A[i].ff){\n                ans[qr.back().ss] = T.lower_bound(q[qr.back().ss][1]) -> ss;\n                qr.pop_back();\n            }\n            upd(b[A[i].ss], A[i].ff + b[A[i].ss]);\n        }\n        return ans;\n    }\n};\n```
['C++']