#K92477. Minimize Difference in Transformed Array
Minimize Difference in Transformed Array
Minimize Difference in Transformed Array
You are given an array of n distinct integers and an integer k. For each element in the array, you are allowed to either subtract k or add k. However, the operation is applied uniformly such that the maximum element is decreased by k and the minimum element is increased by k. Formally, if the array is (b) with (\max(b)) and (\min(b)), then define the transformed maximum as (\max(b) - k) and the transformed minimum as (\min(b) + k). If (\max(b) - k < \min(b) + k), the answer is 0; otherwise, the answer is ((\max(b) - k) - (\min(b) + k)). Your task is to compute this minimum possible difference.
inputFormat
The first line contains two integers n ((1 \leq n \leq 10^5)) and k ((0 \leq k \leq 10^9)). The second line contains n space-separated integers representing the elements of the array b. All elements are distinct.
outputFormat
Output a single integer — the minimal possible difference between the maximum and minimum values in the transformed array.## sample
3 4
1 3 6
0
</p>