You are given an array \(A\) of \(N\) integers. You can perform following operations :
- Choose two distinct indices \(i\) and \(j\), increment \(A_i\) by \(1\) and decrement \(A_j\) by \(1\)
Find the minimum number of operations you should perform such that absolute difference between any two elements is at most \(K\)
Input Format:
The First line contains two integers \(N\) and \(K\) .
The second line contains the \(N\) elements of array \(A\) .
Output Format
Print the minimum number of operations.
Constraints
In first operation we choose i=1 and j=4 so A = [2,5,1,9]
In second operation we choose i=3 and j=4 so A = [2,5,2,8]
In third operation we choose i=1 and j=4 so A = [3,5,2,7]
In fourth operation we choose i=3 and j=4 so A = [3,5,3,6]
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor