Find the Smallest Divisor Given a Threshold
Given an array of integers nums and an integer threshold, choose a positive integer divisor, divide every element of the array by it, and sum the division results.
Each division result is rounded to the nearest integer greater than or equal to that element. For example, 7 / 3 = 3 and 10 / 2 = 5.
Return the smallest divisor such that the sum of these rounded division results is less than or equal to threshold.
The test cases are generated so that there will be an answer.
Example 1
Input
nums = [1,2,5,9], threshold = 6Output
5With divisor 1 the sum is 17, with divisor 4 the sum is 7, and with divisor 5 the sum is 5, so 5 is the smallest divisor that satisfies the threshold.
Example 2
Input
nums = [44,22,33,11,1], threshold = 5Output
44Using divisor 44 makes each rounded division result equal to 1, giving a total sum of 5.
Constraints
- 1 <= nums.length <= 5 * 10^4
- 1 <= nums[i] <= 10^6
- nums.length <= threshold <= 10^6