Score : $300$ points
You are given two sequences, each of length $N$, consisting of integers: $A=(A_1, \ldots, A_N)$ and $B=(B_1, \ldots, B_N)$.
Determine whether there is a sequence of length $N$, $X=(X_1, \ldots, X_N)$, satisfying all of the conditions below.
$X_i = A_i$ or $X_i = B_i$, for every $i(1\leq i\leq N)$.
$|X_i - X_{i+1}| \leq K$, for every $i(1\leq i\leq N-1)$.
Input is given from Standard Input in the following format:
$N$ $K$ $A_1$ $\ldots$ $A_N$ $B_1$ $\ldots$ $B_N$
If there is an $X$ that satisfies all of the conditions, print Yes
; otherwise, print No
.
5 4 9 8 3 7 2 1 6 2 9 5
Yes
$X=(9,6,3,7,5)$ satisfies all conditions.
4 90 1 1 1 100 1 2 3 100
No
No $X$ satisfies all conditions.
4 1000000000 1 1 1000000000 1000000000 1 1000000000 1 1000000000
Yes