#K34802. Smallest Divisor to Achieve Threshold

    ID: 25390 Type: Default 1000ms 256MiB

Smallest Divisor to Achieve Threshold

Smallest Divisor to Achieve Threshold

Given an array of integers and an integer threshold, your task is to find the smallest positive integer divisor such that the sum of the division results of each element, when rounded up to the nearest integer, is less than or equal to the threshold.

For each element \(a\) in the array and a divisor \(d\), the division result is defined as \(\lceil \frac{a}{d} \rceil\), where \(\lceil \cdot \rceil\) denotes the ceiling function.

It is guaranteed that such a divisor exists. An efficient solution using binary search is recommended.

inputFormat

The input is given via stdin and has the following format:

  • The first line contains two space-separated integers: n (the number of elements in the array) and threshold.
  • The second line contains n space-separated integers representing the array elements.

For example:

4 6
1 2 5 9

outputFormat

Output a single integer on stdout representing the smallest divisor that makes the sum of the rounded-up division results for all array elements less than or equal to threshold.

For the sample input above, the output should be:

5
## sample
4 6
1 2 5 9
5