#GYM104598F. Silly Nilly's Stuffies
Silly Nilly's Stuffies
Description
Silly Nilly the intelligent robot has just bought a new shelf with $L$ levels and wants to fill it with stuffed animals. She currently has $P$ piles of $S_i$ stuffed animals each, but since she is a perfectionist, Silly Nilly insists that each layer of the shelf must contain the same number of stuffed animals.
Since she has limited mobility as a robot, in one operation, Silly Nilly can either remove a stuffed animal from any pile or add a stuffed animal to any pile (she has more stuffed animals outside of these piles). Determine the minimum number of operations it will take for Silly Nilly to arrange her piles so that any $L$ piles will have the same number of stuffed animals in them.
Line $1$: Two integers $P$ and $L$
Line $2$: $P$ integers, $S_1$ to $S_P$, denoting the number of stuffed animals in each pile.
Line $1$: An integer representing the minimum number of operations Silly Nilly must complete.
Input
Line $1$: Two integers $P$ and $L$
Line $2$: $P$ integers, $S_1$ to $S_P$, denoting the number of stuffed animals in each pile.
Output
Line $1$: An integer representing the minimum number of operations Silly Nilly must complete.
5 3
9 4 6 2 5
2
Note
$1 <= P <= 10^5$
$1 <= L <= P$
$1 <= S_i <= 10^9$