Room Temperature

면접 대비

시간 제한2초메모리 제한1024 MB

요약
각 장교가 정수 실내 온도에 가장 가깝도록 재킷 수를 고르고, 모든 장교의 최대 불편 지수를 최소화한다.
난이도

보통10점 중 7점

유형
이분 탐색, 수학, 그리디
정답자
아직 제출이 없습니다

문제

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 NN officers in the room. Each officer is numbered from 11 to NN, and the appropriate temperature for officers ii (1≤i≤N1 ≤ i ≤ N) is A_iA\_i degrees when (s)he is not wearing jackets. For each officer, the appropriate temperature drops by TT degrees every time (s)he wears a jacket. In other words, when the officer ii is wearing kk jackets, her/his appropriate temperature is A_i−kTA\_i − kT degrees.

When the room temperature is xx degrees and the appropriate temperature of a certain officer is yy degrees, the discomfort index of the officer is expressed as ∣x−y∣|x − y|. Note that ∣t∣|t| represents the absolute value of tt. Each officer wears the appropriate number of jackets of 00 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.

NN TT

A_1A\_1 A_2A\_2 ⋯\cdots A_NA\_N

출력

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

제한

  • 2≤N≤500,0002 ≤ N ≤ 500\\, 000.
  • 1≤T≤1091 ≤ T ≤ 10^9.
  • 1≤A_i≤1091 ≤ A\_i ≤ 10^9 (1≤i≤N1 ≤ i ≤ N).
  • Given values are all integers.

예제3

  1. 예제 1

    입력
    2 4
    19 24
    
    예상 출력
    1
    
  2. 예제 2

    입력
    3 1
    21 19 23
    
    예상 출력
    0
    
  3. 예제 3

    입력
    6 8
    24 22 21 25 29 17
    
    예상 출력
    2