C++ solution. without segment trees.
\n# Code\n\nclass Solution {\npublic:\n    vector<int> maximumSumQueries(vector<int>& nums1, vector<int>& nums2, vector<vector<int>>& qe) {\n        int n=nums1
\n# Code\n```\nclass Solution {\npublic:\n    vector<int> maximumSumQueries(vector<int>& nums1, vector<int>& nums2, vector<vector<int>>& qe) {\n        int n=nums1.size();\n        vector<pair<int,int>> nums(n);\n        for(int i=0;i<n;i++) nums[i]={nums2[i],nums1[i]};\n        sort(nums.begin(),nums.end());\n        vector<int> sum(n); // store the sum of nums1 and nums2\n        for(int i=0;i<n;i++){\n            sum[i]=nums[i].second+nums[i].first;\n        }\n        stack<int> st;\n    vector<int> ngs(n); // store the next greater of sum at each index\n        for(int i=n-1;i>=0;i--){\n            while(!st.empty() && sum[st.top()]<=sum[i]){\n                st.pop();\n            }\n            if(st.size()==0) ngs[i]=-1;\n            else ngs[i]=st.top();\n            st.push(i);\n        }\n        int q = qe.size();\n        vector<int> ans;\n        for(int i=0;i<q;i++){\n            int n2g=qe[i][1];\n            int n1g=qe[i][0];\n            pair<int,int> p = {n2g,n1g};\n            int idx = lower_bound(nums.begin(),nums.end(),p)-nums.begin();\n            int maxi = -1;\n            while(idx<n && idx!=-1){\n                if(nums[idx].second<n1g){\n                    idx = ngs[idx];\n                    continue;\n                }\n                maxi = max(maxi,sum[idx]);\n                idx = ngs[idx];\n            }\n            ans.push_back(maxi);\n        }\n        return ans;\n    }\n};\n```
['C++']