The problem
Given heights of n towers and a value k. We need to either increase or decrease the height of every tower by k (only once) where k > 0. The task is to minimize the difference between the heights of the longest and the shortest tower after modifications and output this difference.
Constraints
1 ≤ K ≤ 10^4 1 ≤ N ≤ 10^5 1 ≤ Arr[i] ≤ 10^5
Example: K=2, N=4 arr[]= [1,5,8,10]
Output: 5
P.S I already have the solution of GeeksforGeeks but that editorial solution is incorrect.
Can someone share an optimal and correct solution for this problem?
https://mirror.codeforces.com/blog/entry/68823