Smallest Divisor Meeting a Rounded-Sum Limit. Choose a positive integer divisor d. Divide every nums value by d, round each quotient upward to an integer, then sum them.
### Problem
Choose a positive integer divisor d. Divide every nums value by d, round each quotient upward to an integer, then sum them. Return the smallest d whose rounded sum is at most threshold. A feasible divisor exists.
```cpp
class Solution {
public:
int smallestDivisor(vector<int>& nums, int threshold);
};
```
### Examples
**Example 1:**
```text
Input: nums = [3,6,7], threshold = 6
Output: 3
Explanation: Divisor3 gives1+2+3=6. Divisor2 gives2+3+4=9, so no smaller divisor works.
```
**Example 2:**
```text
Input: nums = [4,8], threshold = 2
Output: 8
Explanation: Each term must round to1; this first happens for the largest value at divisor8.
```
### Constraints
- There are 1 to 50000 values, each an integer in `[1,1000000]`.
- `nums.length <= threshold <= 1000000`.
- A feasible divisor exists.
### Contract considerations
All original values are positive. A feasible divisor is guaranteed under the supplied threshold range.
```hint Read the boundary condition
Is a rounded sum equal to threshold permitted, and is the returned value a divisor or the sum?
```
### Boundary reminders
All original values are positive. A feasible divisor is guaranteed under the supplied threshold range.
Overview: Smallest Divisor Meeting a Rounded-Sum Limit. Choose a positive integer divisor d. Divide every nums value by d, round each quotient upward to an integer, then sum them.
Choose a positive integer divisor d. Divide every nums value by d, round each quotient upward to an integer, then sum them. Return the smallest d whose rounded sum is at most threshold. A feasible divisor exists.
class Solution {
public:
int smallestDivisor(vector<int>& nums, int threshold);
};
Examples
Example 1:
Input: nums = [3,6,7], threshold = 6
Output: 3
Explanation: Divisor3 gives1+2+3=6. Divisor2 gives2+3+4=9, so no smaller divisor works.
Example 2:
Input: nums = [4,8], threshold = 2
Output: 8
Explanation: Each term must round to1; this first happens for the largest value at divisor8.
Constraints
There are 1 to 50000 values, each an integer in
[1,1000000]
.
nums.length <= threshold <= 1000000
.
A feasible divisor exists.
Contract considerations
All original values are positive. A feasible divisor is guaranteed under the supplied threshold range.
Boundary reminders
All original values are positive. A feasible divisor is guaranteed under the supplied threshold range.