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.length and make nums1[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
Inputnums1 = [1,2,3], nums2 = [1,2,3], x = 4
Output3
Applying 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
Inputnums1 = [1,2,3], nums2 = [3,3,3], x = 4
Output-1
The 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

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate