시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB2551059643.636%

문제

President K is taking on the role of adjusting the room temperature of the officers’ room. He wants to make the officers as comfortable as possible.

Now there are $N$ officers in the room. Each officer is numbered from $1$ to $N$, and the appropriate temperature for officers $i$ ($1 ≤ i ≤ N$) is $A_i$ degrees when (s)he is not wearing jackets. For each officer, the appropriate temperature drops by $T$ degrees every time (s)he wears a jacket. In other words, when the officer $i$ is wearing $k$ jackets, her/his appropriate temperature is $A_i − kT$ degrees.

When the room temperature is $x$ degrees and the appropriate temperature of a certain officer is $y$ degrees, the discomfort index of the officer is expressed as $|x − y|$. Note that $|t|$ represents the absolute value of $t$. Each officer wears the appropriate number of jackets of $0$ or more to minimize discomfort index, depending on the room temperature.

Here, president K decided to call the maximum discomfort index among all officers as room’s unpleasantness, and set the room temperature so that the room’s unpleasantness was minimized. Note that the room temperature must be an integer.

Write a program which, given information about the officers and the appropriate temperature, calculates the minimum room’s unpleasantness.

입력

Read the following data from the standard input.

$N$ $T$

$A_1$ $A_2$ $\cdots$ $A_N$

출력

Write one line to the standard output. The output should contain the minimum room’s unpleasantness.

제한

  • $2 ≤ N ≤ 500\, 000$.
  • $1 ≤ T ≤ 10^9$.
  • $1 ≤ A_i ≤ 10^9$ ($1 ≤ i ≤ N$).
  • Given values are all integers.

서브태스크

번호배점제한
115

$N = 2$.

25

$N ≤ 3\, 000$, $T = 1$.

330

$N ≤ 3\, 000$, $T ≤ 2$.

435

$N ≤ 3\, 000$, $T ≤ 3\, 000$.

515

No additional constraints.

예제 입력 1

2 4
19 24

예제 출력 1

1

For example, if the room temperature is set to $16$ degrees, the appropriate temperature for officer $1$ will be $15$ degrees by wearing one jacket; the discomfort index is $|16 - 15| = 1$. The appropriate temperature for officer $2$ will be $16$ degrees by wearing two jackets; the discomfort index is $|16 - 16| = 0$. At this time, the room’s unpleasantness becomes $1$.

Since the room’s unpleasantness cannot be made smaller than $1$, output $1$.

This sample input satisfies the constraints of Subtasks 1, 4, 5.

예제 입력 2

3 1
21 19 23

예제 출력 2

0

For example, if the room temperature is set to $19$ degrees, the room’s unpleasantness becomes $0$. Output $0$.

This sample input satisfies the constraints of Subtasks 2, 3, 4, 5.

예제 입력 3

6 8
24 22 21 25 29 17

예제 출력 3

2

For example, if the room temperature is set to $15$ degrees, the room’s unpleasantness becomes $2$. Since the room’s unpleasantness cannot be made smaller than $2$, output $2$.

This sample input satisfies the constraints of Subtasks 4, 5.

채점 및 기타 정보

  • 예제는 채점하지 않는다.