100% beats solution O(NLOGN + LOGM + LOGN) TC
\n\n# Code\n\nclass Solution {\npublic:\n    vector<int> maximumSumQueries(vector<int>& nums1, vector<int>& nums2, vector<vector<int>>& queries) {\n        vect
\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> maximumSumQueries(vector<int>& nums1, vector<int>& nums2, vector<vector<int>>& queries) {\n        vector<vector<int>> vp;\n        int n = queries.size();\n        for(int i = 0; i < n; i++)\n            vp.push_back({queries[i][0], queries[i][1], i});\n        \n        sort(vp.begin(), vp.end(), [](vector<int> &a, vector<int> &b) {\n            return a[0] == b[0] ? a[1] < b[1] : a[0] < b[0];\n        });\n\n        priority_queue<vector<int>> p,q;\n        for(int i = 0; i < nums1.size(); i++) \n            p.push({nums1[i] + nums2[i], nums1[i], nums2[i]});\n\n        vector<int> ans(n, -1);\n        for(auto v: vp) {\n            while(!p.empty()) {\n                if(p.top()[1] < v[0])\n                    p.pop();\n                // first is greater and second is smaller then keep it save in next queue because it can be use further\n                else if(p.top()[2] < v[1]) \n                    q.push(p.top()), p.pop();\n                else \n                    break;\n            }\n\n            if(!p.empty())\n                ans[v[2]] = p.top()[0];\n            \n            while(!q.empty()) \n                p.push(q.top()), q.pop();\n        }\n\n        return ans;\n    }\n};\n```
['C++']