#agc057b. [agc057_b]2A + x
[agc057_b]2A + x
Problem Statement
You are given a sequence of positive integers and a positive integer . You can perform the operation below any number of times, possibly zero:
- Choose an index () and a non-negative integer such that . Change to .
Find the smallest possible value of $\\max\\{A_1,A_2,\\ldots,A_N\\}-\\min\\{A_1,A_2,\\ldots,A_N\\}$ after your operations.
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print the smallest possible value of $\\max\\{A_1,A_2,\\ldots,A_N\\}-\\min\\{A_1,A_2,\\ldots,A_N\\}$ after your operations.
Sample Input 1
4 2
5 8 12 20
Sample Output 1
6
Let denote an operation that changes to . An optimal sequence of operations is
- , , ,
which yields , achieving $\\max\\{A_1,A_2,A_3,A_4\\}-\\min\\{A_1,A_2,A_3,A_4\\} = 6$.
Sample Input 2
4 5
24 25 26 27
Sample Output 2
0
An optimal sequence of operations is
- , , , , , , ,
which yields , achieving $\\max\\{A_1,A_2,A_3,A_4\\}-\\min\\{A_1,A_2,A_3,A_4\\} = 0$.
Sample Input 3
4 1
24 25 26 27
Sample Output 3
3
Performing no operations achieves $\\max\\{A_1,A_2,A_3,A_4\\}-\\min\\{A_1,A_2,A_3,A_4\\} = 3$.
Sample Input 4
10 5
39 23 3 7 16 19 40 16 33 6
Sample Output 4
13