Logo
(追記) (追記ここまで)

31623번 - Room Temperature 서브태스크다국어

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

문제

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.

힌트

출처

Olympiad > Japanese Olympiad in Informatics > JOI 2023/2024 1번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /