[JS] 330ms, 105mb desc sort sum, cache result
Intuition\n Describe your first thoughts on how to solve this problem. \ndescending sort based on sum, realized that sort based on x or y will fail\n\n# Approac
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\ndescending sort based on sum, realized that sort based on x or y will fail\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- eliminate queries that exceed max x or y\n- search starting from highest max sum\n- cache result, so next query dont have to search again\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    const result = []\n    const maxs = []\n    const memc = {}\n    for(let i = 0; i < nums1.length; i++){\n        let x = nums1[i], y = nums2[i]\n        maxs.push({x, y})\n    }\n    maxs.sort((a, b) => (b.x + b.y) - (a.x + a.y))\n    nums1.sort((a, b) => b-a)\n    nums2.sort((a, b) => b-a)\n\n    const mx = nums1[0]\n    const my = nums2[0]\n\n    for(let j = 0; j < queries.length; j++){\n        const q = queries[j]\n        const qx = q[0], qy = q[1]\n        const ck = qx + "," + qy\n\n        if(qx > mx || qy > my){\n            memc[ck] = -1\n            result.push(-1)\n            continue;\n        }\n\n        if(memc[ck]){\n            result.push(memc[ck])\n            continue\n        }\n\n        result.push(-1)\n        \n        for(let i = 0; i < maxs.length; i++){\n            const cs = maxs[i]\n            if(qx <= cs.x && qy <= cs.y){\n                memc[ck] = cs.x + cs.y\n                result[result.length-1] = cs.x + cs.y\n                break;\n            }\n        }\n    }\n\n\n    return result\n};\n```
['JavaScript']