#P10205. [JOI 2024 Final] 室温 / Room Temperature

[JOI 2024 Final] 室温 / Room Temperature

Problem Description

Chairman K is responsible for adjusting the room temperature for the executives. He wants them to work as comfortably as possible.

There are NN executives in the room. Each executive is assigned an ID from 11 to NN. Without wearing a coat, executive i (1iN)i\ (1 \leq i \leq N) has a comfortable temperature of AiA_i degrees. Also, for each coat an executive wears, their comfortable temperature decreases by TT degrees. That is, if executive ii wears kk coats, then executive ii's comfortable temperature becomes AikTA_i - kT degrees.

If the room temperature is xx degrees and an executive's comfortable temperature is yy degrees, then this executive's discomfort is xy|x - y|, where t|t| denotes the absolute value of tt. Each executive will, depending on the room temperature, wear an appropriate number of coats k0k \geq 0 to minimize their discomfort.

Chairman K defines the maximum discomfort among all executives as the room's discomfort, and he decides to set the room temperature to a value that minimizes the room's discomfort. However, the chosen temperature must be an integer.

Given the information about the executives and their comfortable temperatures, write a program to find the minimum possible value of the room's discomfort.

Input Format

The first line contains two integers N,TN, T.

The second line contains NN integers A1,A2,,ANA_1, A_2, \ldots, A_N separated by spaces.

Output Format

Output one integer on a single line, representing the minimum possible value of the room's discomfort.

2 4
19 24
1
3 1
21 19 23
0
6 8
24 22 21 25 29 17
2

Hint

For all input data, the following constraints hold:

  • 2N5×1052 \leq N \leq 5\times 10^5
  • 1T1091 \leq T \leq 10^{9}
  • 1Ai109(1iN)1 \leq A_i \leq 10^{9}(1 \leq i \leq N)

The detailed additional constraints and scores for each subtask are shown in the table below.

Subtask Additional Constraints Score
1 N=2N=2 15
2 N3000,T=1N \leq 3000, T=1 5
3 N3000,T2N \leq 3000, T \leq 2 30
4 N3000,T3000N \leq 3000, T \leq 3000 35
5 No additional constraints 15

Translated by ChatGPT 5