JS solution with segment tree, coordinate compression and 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```\n/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar maximumSumQueries = function(nums1, nums2, queries) {\n    let n = nums1.length;\n    let m = queries.length;\n    function binarySearch(arr, l, r, x) {\n        while (l < r) {\n            let mid = Math.floor(l + (r-l)/2);\n             if (arr[mid][0] < x) {\n                l = mid+1;\n            } else {\n                r = mid;\n            }\n        }\n        return arr[l][0] >= x ? l : -1;\n    }\n    let pairArray = [];\n    for (let i=0; i < nums1.length; i++) {\n        pairArray.push([nums1[i], nums2[i]]);\n    }\n    let set = new Set();\n    for(let y of nums2) {\n        set.add(y);\n    }\n    for (let q of queries) {\n        set.add(q[1]);\n    }\n    let sortedSet = [...set].sort((a, b) => a-b);\n    let tdx = 0;\n    let cord = {};\n    for (let x of sortedSet) {\n        cord[x] = tdx;\n        tdx++;\n    }\n\n    pairArray.sort((a, b) => a[0] - b[0]);\n    for(let i = 0 ; i < m ; ++i)\n        queries[i].push(i);\n    queries.sort((a, b) => b[0] - a[0]);\n\n    let seg = Array.from({length: 4*tdx}, () => -1);\n\n    function update(node, ind, val, l, r) {\n        if (l === r) {\n            seg[node] = Math.max(val, seg[node]);\n            return;\n        }\n        let mid = Math.floor(l + (r-l)/2);\n        if (ind <= mid) {\n            update(2*node + 1, ind, val, l, mid);\n        } else {\n            update(2*node+2, ind, val, mid+1, r);\n        }\n        seg[node] = Math.max(seg[2*node + 1], seg[2*node + 2]);\n    }\n    function querySegTree(ql, qr, l, r, node) {\n        if (ql > r || qr < l)\n            return -1;\n        if (ql<=l && qr >= r) {\n            return seg[node];\n        }\n        let mid = Math.floor(l + (r-l)/2);\n        let leftTree = querySegTree(ql, qr, l, mid, 2*node + 1);\n        let rightTree = querySegTree(ql, qr, mid+1, r, 2*node + 2);\n        return Math.max(leftTree, rightTree); \n    }\n\n    let k = n-1;\n    let ans = Array.from({ length: m }, () => -1);\n    for (let i=0; i < queries.length; i++) {\n        let ql = queries[i][0];\n        let qr = queries[i][1];\n        let ansInd = queries[i][2];\n        let ind = binarySearch(pairArray, 0, n-1, ql);\n        while(k >= ind && ind !== -1) {\n            update(0, cord[pairArray[k][1]], pairArray[k][0]+pairArray[k][1], 0, tdx-1);\n            k--;\n        }\n        let res = querySegTree(cord[qr], tdx-1, 0, tdx-1, 0);\n        ans[ansInd] = res;\n    }\n    return ans;\n};\n```
['JavaScript']