#C3316. Monkey Jump Reachability
Monkey Jump Reachability
Monkey Jump Reachability
A monkey is attempting to jump across a series of pillars. The pillars are arranged in increasing order of their positions on a line. The monkey starts at the first pillar and must reach the last pillar. The monkey can only jump from one pillar to the next if the distance between consecutive pillars is an exact multiple of a fixed integer d. In mathematical terms, for all valid i (where 1 ≤ i < n), the jump is allowed only if
\((p_{i+1} - p_i) \bmod d = 0\)
where \(p_i\) is the position of the i-th pillar. Your task is to determine whether the monkey can successfully reach the last pillar by checking every consecutive jump.
inputFormat
The first line contains two integers n and d, where n (n ≥ 2) is the number of pillars and d is the fixed jump divisor.
The second line contains n space-separated integers representing the positions of the pillars in strictly increasing order.
outputFormat
Output a single line containing YES
if the monkey can reach the last pillar, or NO
otherwise.
5 3
1 4 7 10 13
YES