#K54412. Electric Car Journey
Electric Car Journey
Electric Car Journey
You are given a series of cities positioned on a straight line. An electric car is able to travel a maximum distance of \(d\) in one go. Starting from the first city, the car must travel consecutively from one city to the next. Your task is to determine whether it is possible for the car to travel from the first city to the last city without ever having to travel a distance greater than \(d\) in a single move.
Note: The cities are given in order of increasing distance, and the travel between adjacent cities must not exceed the maximum distance \(d\). If any gap exceeds \(d\), the journey cannot be completed.
inputFormat
The input is given via standard input (stdin) and consists of the following:
- The first line contains two integers \(n\) and \(d\), where \(n\) is the number of cities and \(d\) is the maximum distance the car can travel in one go.
- The second line contains \(n\) integers, representing the coordinates of the cities in increasing order.
outputFormat
Output a single line to standard output (stdout) containing YES
if it is possible for the car to travel from the first to the last city, or NO
otherwise.
5 5
0 3 7 10 14
YES