Rabbit Carrot | 프로그래밍의 벗 PivotOJ
PivotOJ

Rabbit Carrot

시간 제한: 1000ms메모리 제한: 1024MB출처: LMIO 2018-2019BOJ 27347
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

Rabbit called Carrot is willing to cross the bridge. The bridge consists of NN poles of different height. Carrot can jump at most MM centimeters up and any distance down.

[이미지 1]

The rabbit starts crossing the bridge from the left and is standing at height zero immediately before the first pole. The goal of the Carrot is to reach the other side of the bridge by jumping on each pole in order.

However, it might happen, that the rabbit will not be able to jump on some poles as it will be too high.

Help the rabbit Carrot to cross the bridge by modifying the heights of some poles. Calculate the smallest possible amount of poles the height of which has to be either increased or decreased so that the Carrot could cross the bridge. Height of each of the poles can be increased by any amount and decreased to a non-negative value.

입력

The first line contains two integers: the number of bridge poles NN and the Carrot leap-up size MM. The following NN lines contain the heights of the poles aia_i given as integers one number per line.

출력

Output one integer – the least number of poles that have to be either lifted or lowered so that the rabbit Carrot could cross the bridge.

예제

예제 1

입력
5 400
300
700
200
1000
500
출력
1

예제 2

입력
3 300
700
1000
1300
출력
3
코드를 제출하려면 로그인하세요.