python with inline explaination
Intuition\n Describe your first thoughts on how to solve this problem. \nWe can remove nums2 from small to big to let nums1 increase slower.\n\n# Approach\n Des
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can remove nums2 from small to big to let nums1 increase slower.\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)$$ -->\nO(n^2)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n# Code\n```\nclass Solution(object):\n    def minimumTime(self, nums1, nums2, x):\n        """\n        :type nums1: List[int]\n        :type nums2: List[int]\n        :type x: int\n        :rtype: int\n        s1+s2*n\n\n        remove smallest nums2[?] pair from 0~i\n        dp[i-1]+nums1[i]+nums2[i]*i\n        """\n        n=len(nums1)\n        dp=[0]*(n+1)\n        idx=range(n)\n        idx.sort(key=lambda x:nums2[x])\n        for i in range(1,n+1): # remove nums2 small to big\n            for j in range(i,0,-1): #at j sec remove the biggest nums2 for dp[j], 2nd biggest for dp[j-1]\n                dp[j]=max(dp[j],dp[j-1]+nums1[idx[i-1]]+nums2[idx[i-1]]*j)\n        s1,s2=sum(nums1),sum(nums2)\n        for i in range(0,n+1):# start from i==0, means no need to remove any element\n            if s1+s2*i-dp[i]<=x:\n                return i\n        return -1\n\n```
['Python']