amounts and an integer limit. Pick an integer divisor d ≥ 1, divide every number in the array by it rounding **up** (so 7 / 3 gives 3 and 10 / 2 gives 5), and add up the results.
Find the smallest d for which this sum is at most limit.
The value of limit is guaranteed to be at least the array length, so a suitable divisor always exists.amounts=[3, 8, 14], limit=5 → 7
With divisor 6 the sum is 1 + 2 + 3 = 6, which exceeds 5. With divisor 7 it is 1 + 2 + 2 = 5, which fits.
amounts=[6, 6], limit=12 → 1
Divisor 1 already gives a sum of 12, and no divisor is smaller.
amounts=[3, 8, 14], limit=5
7
Run checks the first 3 tests in your browser. Submit checks all 58 tests on the server, hidden ones included.