c++ solution using fenwick tree
\nclass Solution {\npublic:\n    const int N=2e5+10;\n    int bit[210000];\n    void update(int i,int sum)\n    {\n        i++;\n        while(i<N)\n        {\n
```\nclass Solution {\npublic:\n    const int N=2e5+10;\n    int bit[210000];\n    void update(int i,int sum)\n    {\n        i++;\n        while(i<N)\n        {\n            bit[i]=max(bit[i],sum);\n            i+=(i&-i);\n        }\n    }\n    int find(int i)\n    {\n        i++;\n        int max_sum=-1;\n        while(i>0)\n        {\n            max_sum=max(max_sum,bit[i]);\n            i-=(i&-i);\n        }\n        return max_sum;\n    }\n    vector<int> maximumSumQueries(vector<int>& nums1, vector<int>& nums2, vector<vector<int>>& q)\n    {\n        memset(bit,-1,sizeof(bit));\n        int n=nums1.size();\n        vector<pair<int,int>>nums;\n        set<int>s;\n        for(int i=0;i<n;i++)\n        {\n            s.insert(nums2[i]);\n            nums.push_back({nums1[i],nums2[i]});\n        }\n        for(int i=0;i<q.size();i++)\n        {\n            s.insert(q[i][1]);\n            q[i].push_back(i);\n        }\n        map<int,int>id;\n        int index=s.size();\n        for(auto it:s)\n        {\n            id[it]=index--;\n        }\n        sort(nums.rbegin(),nums.rend());\n        sort(q.rbegin(),q.rend());\n        vector<int>ans(q.size(),-1);\n        for(int i=0,j=0;i<q.size();i++)\n        {\n            int x=q[i][0];\n            int y=id[q[i][1]];\n            int index=q[i][2];\n            while(j<n&&nums[j].first>=x)\n            {\n                update(id[nums[j].second],nums[j].first+nums[j].second);\n                j++;\n            }\n            ans[index]=find(y);\n        }\n        return ans;\n    }\n};   \n```
['C', 'C++']