atcoder#AGC057B. [AGC057B] 2A + x
[AGC057B] 2A + x
Score : points
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.
4 2
5 8 12 20
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$.
4 5
24 25 26 27
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$.
4 1
24 25 26 27
3
Performing no operations achieves $\max\{A_1,A_2,A_3,A_4\}-\min\{A_1,A_2,A_3,A_4\} = 3$.
10 5
39 23 3 7 16 19 40 16 33 6
13