Segment Tree  C++
\n#define ff first\n#define ss second\n#define pi pair<int,int>\nclass segment_tree{\npublic:\n    vector<long long> t;\n    int n;\n    segment_tree(int x){\n 
```\n#define ff first\n#define ss second\n#define pi pair<int,int>\nclass segment_tree{\npublic:\n    vector<long long> t;\n    int n;\n    segment_tree(int x){\n        n = x;\n        t.resize(x*2, 0);\n        for(auto & i : t) i = -1e9;\n    }\n    void up(int pos, long long val){\n        for(t[pos+=n] = val; pos > 1; pos >>= 1) t[pos/2] = max(t[pos],t[pos^1]);\n    }\n    int qu(int a, int b){\n        long long res = -1e9;\n        for(int l = a+n, r = b+n+1; l < r; l >>= 1, r >>= 1){\n            if(l & 1) res = max(res, t[l++]);\n            if(r & 1) res = max(res, t[--r]);\n        }\n        return res;\n    }\n    \n    \n    \n};\n\nclass Solution {\npublic:\n    vector<int> maximumSumQueries(vector<int>& a, vector<int>& b, vector<vector<int>>& q) {\n        vector<pi> st,v;\n        \n        for(int i=0; i<a.size(); ++i)\n        {\n            // if(st.size()==0)\n                st.push_back({a[i],b[i]});\n        }\n        \n        sort(st.rbegin(),st.rend());\n        vector<pi> tem;\n        v.push_back(st[0]);\n        int ix = 0;\n        tem.push_back({st[0].ss,ix++});\n        for(int i=0; i<st.size(); ++i)\n        {\n            pi p = v.back();\n            if(p.ff>=st[i].ff && p.ss>=st[i].ss)\n                continue;\n            v.push_back(st[i]);\n            tem.push_back({st[i].ss,ix++});\n        }\n        \n        sort(tem.begin(),tem.end());\n        map<int,vector<int>> id;\n        for(auto x:tem)\n        {\n            id[x.ff].push_back(x.ss);\n        }\n        \n        segment_tree tr(v.size());\n        \n        int n = v.size();\n\n        for(int i=0; i<q.size(); ++i)\n        {\n            q[i].push_back(i);\n            int r = 0,l = n-1;\n            while(r<=l)\n            {\n                int mid = (r+l)/2;\n                if(v[mid].ff<q[i][0])\n                    l = mid-1;\n                else\n                    r = mid+1;\n            }\n            \n            q[i].push_back(l);\n            swap(q[i][0],q[i][3]);\n            swap(q[i][1],q[i][2]);\n        }\n        \n        sort(q.begin(),q.end());\n            \n        int pre = 0;\n        vector<int> fans(q.size());\n        for(int i=0; i<q.size(); ++i)\n        {\n                \n            while(pre<=q[i][0])\n            {\n                int sum = v[pre].ff+v[pre].ss;\n                int ix = id[v[pre].ss].back();\n                tr.up(ix,sum);\n                pre++;\n            }\n            \n            int tt = q[i][2];\n            int r = 0,l = n-1;\n            while(r<=l)\n            {\n                int mid = (r+l)/2;\n                if(tem[mid].ff>=tt)\n                    l = mid-1;\n                else\n                    r = mid+1;\n            }\n            \n            fans[q[i][1]] = tr.qu(l+1,n-1);\n        }\n        \n        for(int &x:fans)\n            if(x==-1e9)\n                x = -1;\n        \n        return fans;\n        \n        \n    }\n};\n```
['C']