#K46847. Minimize the Maximum Element
Minimize the Maximum Element
Minimize the Maximum Element
You are given an array of integers. You can perform a series of allowed operations (possibly redistributing the total sum among the elements) in order to minimize the maximum element in the array. Your task is to compute the minimum possible value of the maximum element achievable through these operations.
A key observation is that the minimum possible maximum value is equal to the ceiling of the average value of the array. In mathematical terms, if the array contains n elements with a total sum S, then the answer is given by:
[ \lceil \frac{S}{n} \rceil = \frac{S + n - 1}{n} ]
It is guaranteed that the array has at least one element.
inputFormat
The input is given via standard input (stdin). The first line contains an integer n (1 ≤ n ≤ 10^5), which is the number of elements in the array. The second line contains n space-separated integers representing the elements of the array. Each element is in the range [1, 10^9].
outputFormat
Output a single integer — the minimized maximum value after performing the allowed operations.## sample
3
2 5 3
4