Minimum Time to Make Array Sum At Most x
You are given two 0-indexed integer arrays nums1 and nums2 of equal length. Every second, for all indices 0 <= i < nums1.length, the value of nums1[i] is incremented by nums2[i]. After this is done, you can perform the following operation:
- Choose an index
0 <= i < nums1.lengthand makenums1[i] = 0.
You are also given an integer x.
Return the minimum time in which you can make the sum of all elements of nums1 be less than or equal to x, or -1 if this is not possible.
Example 1
Input
nums1 = [1,2,3], nums2 = [1,2,3], x = 4Output
3Applying the operation to indices 0, 1, and 2 over three seconds results in
nums1 = [2, 2, 0] with sum 4, which is optimal.Example 2
Input
nums1 = [1,2,3], nums2 = [3,3,3], x = 4Output
-1The sum of
nums1 will always be greater than x, no matter which operations are performed.Constraints
- 1 <= nums1.length <= 10^3
- 1 <= nums1[i] <= 10^3
- 0 <= nums2[i] <= 10^3
- nums1.length == nums2.length
- 0 <= x <= 10^6