Easy || sorting+seg+binary_search
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\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nvector<pair<int,int>> v;\nclass mergesort_tree{\n    private:\n     int n;\n     struct node{\n        int x,y,sum;\n     };\n     vector<vector<node>> t;\n     vector<node> merge(vector<node>&a ,vector<node>&b){\n        vector<node> temp;\n        int n1=a.size();\n        int n2=b.size();\n        int i=0,j=0;\n        int k=0;\n        temp.resize(n1+n2);\n        while(i<n1 && j<n2){\n            if(a[i].y<b[j].y){\n                temp[k]=a[i];\n                i++;\n                k++;\n\n            }\n            else{\n                 temp[k]=b[j];\n                j++;\n                k++;\n\n            }\n        }\n        while(i<n1){\n            temp[k]=a[i];\n                i++;\n                k++;\n        }\n        while(j<n2){\n               temp[k]=b[j];\n                j++;\n                k++;\n\n        }\n        for(int i=temp.size()-2;i>=0;i--){\n            temp[i].sum=max(temp[i].sum,temp[i+1].sum);\n        }\n        return temp;\n\n\n     }\n     void build(int id,int l,int r){\n        if(l==r){\n            t[id]={{v[l].first,v[l].second,v[l].first+v[l].second}};\n            return ;\n        }\n        int mid=(l+r)/2;\n        build(2*id,l,mid);\n        build(2*id+1,mid+1,r);\n       t[id]=merge(t[2*id],t[2*id+1]);\n\n     }\n     int binary_search(vector<node>&a,int val){\n        int lo=0,hi=a.size()-1;\n        int ans=-1;\n        while(lo<=hi){\n            int mid=(lo+hi)/2;\n            if(a[mid].y>=val){\n                ans=mid;\n                hi=mid-1;\n            }\n            else{\n                lo=mid+1;\n            }\n        }\n        return ans;\n     }\n     int query(int id,int l,int r,int lq,int rq,int val){\n        if(l>rq || r<lq) return -1;\n        if(lq<=l && r<=rq){\n            int idx=binary_search(t[id],val);\n            if(idx!=-1) return t[id][idx].sum;\n            return -1;\n        }\n        int mid=(l+r)/2;\n        int left=query(2*id,l,mid,lq,rq,val);\n        int right=query(2*id+1,mid+1,r,lq,rq,val);\n        return max(left,right);\n     }\n     public:\n     mergesort_tree(int n){\n        this->n=n;\n        t.resize(4*n);\n        build(1,0,n-1);\n     }\n     int query(int l,int r,int y){\n        return query(1,0,n-1,l,r,y);\n     }\n\n};\nclass Solution {\npublic:\n    vector<int> maximumSumQueries(vector<int>& nums1, vector<int>& nums2, vector<vector<int>>& queries) {\n        int n=nums1.size();\n        vector<int> ans;\n        v.resize(n);\n        for(int i=0;i<n;i++){\n            v[i]={nums1[i],nums2[i]};\n        }\n        sort(v.begin(),v.end());\n        mergesort_tree mt(n);\n        for(auto q:queries){\n            int x=q[0],y=q[1];\n            int l=lower_bound(v.begin(),v.end(),make_pair(x,-1))-v.begin();\n            int res=mt.query(l,n-1,y); // from l to n-1 ,find maximum sum such that B[l--n-1]>=y;\n            ans.push_back(res);\n        }\n        return ans;\n        \n    }\n};\n```
['Binary Search', 'Segment Tree', 'Sorting', 'C++']