java script - Minimum Time to Make Array Sum At Most x
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} x\n * @return {number}\n */\n// var minimumTime = function(nums1, nums2, x) {\n    \n// };\n\nfunction minimumTime(nums1, nums2, x) {\n    const n = nums1.length;\n    const ind = new Array(n);\n    let s = 0;\n    let d = 0;\n\n    for (let i = 0; i < n; ++i) {\n        ind[i] = i;\n        s += nums1[i];\n        d += nums2[i];\n    }\n\n    if (s <= x) {\n        return 0;\n    }\n\n    ind.sort((a, b) => {\n        return nums2[a] - nums2[b];\n    });\n\n    const dp = new Array(n + 1).fill(0);\n    let r = n + 1;\n\n    for (let i = 1; i <= n; ++i) {\n        for (let j = Math.min(i, r - 1); j; --j) {\n            dp[j] = Math.max(dp[j], dp[j - 1] + nums2[ind[i - 1]] * j + nums1[ind[i - 1]]);\n\n            if (s + j * d - dp[j] <= x) {\n                r = j;\n            }\n        }\n    }\n\n    return r <= n ? r : -1;\n}\n\n// Example usage:\nconst nums1 = [1, 2, 3];\nconst nums2 = [4, 5, 6];\nconst x = 10;\n\nconsole.log(minimumTime(nums1, nums2, x)); // Output: 2\n\n\n\n\n```
['JavaScript']