Python | DP | O(n^2)
Code\n\nclass Solution:\n    def minimumTime(self, nums1: List[int], nums2: List[int], x: int) -> int:\n        sum1 = sum(nums1)\n        if sum1 <= x: return 
# Code\n```\nclass Solution:\n    def minimumTime(self, nums1: List[int], nums2: List[int], x: int) -> int:\n        sum1 = sum(nums1)\n        if sum1 <= x: return 0\n        sum2 = sum(nums2)\n        nums = sorted(list(zip(nums2, nums1)))\n        n = len(nums)\n        dp = [0]*n\n        for k in range(1,n+1):\n            newdp = [0]*n\n            for i in range(k-1, n):\n                newdp[i] = max(newdp[i-1] if i else 0,(dp[i-1] if i else 0)+nums[i][0]*k+nums[i][1])\n            if sum1 + k*sum2 - newdp[-1] <= x:\n                return k\n            dp = newdp\n        return -1\n```
['Python3']