atcoder#ABC245C. [ABC245C] Choose Elements

[ABC245C] Choose Elements

Score : 300300 points

Problem Statement

You are given two sequences, each of length NN, consisting of integers: A=(A1,,AN)A=(A_1, \ldots, A_N) and B=(B1,,BN)B=(B_1, \ldots, B_N).

Determine whether there is a sequence of length NN, X=(X1,,XN)X=(X_1, \ldots, X_N), satisfying all of the conditions below.

  • Xi=AiX_i = A_i or Xi=BiX_i = B_i, for every i(1iN)i(1\leq i\leq N).
  • XiXi+1K|X_i - X_{i+1}| \leq K, for every i(1iN1)i(1\leq i\leq N-1).

Constraints

  • 1N2×1051 \leq N \leq 2\times 10^5
  • 0K1090 \leq K \leq 10^9
  • 1Ai,Bi1091 \leq A_i,B_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

A1A_1 \ldots ANA_N

B1B_1 \ldots BNB_N

Output

If there is an XX 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)X=(9,6,3,7,5) satisfies all conditions.

4 90
1 1 1 100
1 2 3 100
No

No XX satisfies all conditions.

4 1000000000
1 1 1000000000 1000000000
1 1000000000 1 1000000000
Yes