As hinted
Note the dp should not be done with python builtin memoization which would cause MLE, in stead, do the tabulation yourself\n\n# Code\n\nclass Solution:\n    def
Note the dp should not be done with python builtin memoization which would cause MLE, in stead, do the tabulation yourself\n\n# Code\n```\nclass Solution:\n    def minimumTime(self, nums1: List[int], nums2: List[int], x: int) -> int:\n        n = len(nums1)\n        nums = [(n1,n2) for n1,n2 in zip(nums1,nums2)]\n        nums.sort(key = lambda x:x[1])\n        nowsum = sum([x[0] for x in nums])\n        if nowsum <= x: return 0\n        dp = [[0 for i in range(n+1)] for j in range(n)]\n        for i in range(n):\n            for t in range(n+1):\n                if t == 0:\n                    dp[i][t] =0\n                else:\n                    dp[i][t] = max(dp[i-1][t],dp[i-1][t-1] + nums[i][1]*t + nums[i][0])\n\n        sA = sum(nums1)\n        sB = sum(nums2)\n        for t in range(n+1):\n            if sA+sB*t -dp[n-1][t]<=x:\n                return t\n        return -1\n\n        \n```
['Python3']