#C3187. Minimize Water Level Difference
Minimize Water Level Difference
Minimize Water Level Difference
You are given N water tanks with initial water levels given by an array \(A\) of integers. You also have at most K units of water available, where each unit can increase the water level of a single tank by one. Your goal is to minimize the difference between the maximum and minimum water levels after performing at most K operations.
In each operation, you can choose a tank and add one unit of water to it. Formally, if the water levels are \(A_1, A_2, \dots, A_N\) initially, you need to determine the minimum possible value of
[ \min (\max_{1 \leq i \leq N} A_i' - \min_{1 \leq i \leq N} A_i') ]
where \(A_i'\) represents the water level of the \(i\)-th tank after adding water with at most \(K\) total operations.
Note: The operations can only increase the water levels of the tanks. It is not allowed to remove water from any tank.
inputFormat
The first line contains two integers \(N\) and \(K\) (1 \(\leq N \leq 10^5\), 0 \(\leq K \leq 10^9\)) representing the number of tanks and the maximum number of operations, respectively.
The second line contains \(N\) space-separated integers \(A_1, A_2, \dots, A_N\) (each \(A_i\) satisfying \(0 \leq A_i \leq 10^9\)) representing the initial water levels in the tanks.
outputFormat
Output a single integer which is the minimum possible difference between the maximum and minimum water levels after performing at most \(K\) operations.
## sample5 10
1 5 7 10 12
7
</p>