Given an array of integers nums and an integer threshold, choose a positive integer divisor, divide every element of nums by it, round each quotient up to the nearest integer, and add the results. Return the smallest divisor for which this sum is less than or equal to threshold. The tests guarantee that an answer exists.
Given an array of integers nums and an integer threshold, choose a positive integer divisor, divide every element of nums by it, round each quotient up to the nearest integer, and add the results. Return the smallest divisor for which this sum is less than or equal to threshold. The tests guarantee that an answer exists.
Example 1:
Input: {"nums":[1,2,5,9],"threshold":6}
Output: 5
Constraints:
1≤nums.length≤5×104
1≤nums[i]≤106
nums.length≤threshold≤106
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[1,2,5,9],"threshold":6}
Dividing by d cuts each number into ceil(x / d) pieces. A bigger d means fewer pieces, so the piece count only falls as d grows.