#abc245c. C - Choose Elements

C - Choose Elements

Score : 300300 points

问题描述

给定两个长度均为 NN 的整数序列:A=(A1,,AN)A=(A_1, \ldots, A_N)B=(B1,,BN)B=(B_1, \ldots, B_N)

确定是否存在一个长度为 NN 的序列 X=(X1,,XN)X=(X_1, \ldots, X_N),满足以下所有条件:

  • 对于每个 i(1iN)i(1\leq i\leq N),有 Xi=AiX_i = A_i 或者 Xi=BiX_i = B_i

  • 对于每个 i(1iN1)i(1\leq i\leq N-1),满足 XiXi+1K|X_i - X_{i+1}| \leq K

以上为通义千问 qwen-max 翻译,仅供参考。

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.

Sample Input 1

5 4
9 8 3 7 2
1 6 2 9 5

Sample Output 1

Yes

X=(9,6,3,7,5)X=(9,6,3,7,5) satisfies all conditions.

Sample Input 2

4 90
1 1 1 100
1 2 3 100

Sample Output 2

No

No XX satisfies all conditions.

Sample Input 3

4 1000000000
1 1 1000000000 1000000000
1 1000000000 1 1000000000

Sample Output 3

Yes

update @ 2024/3/10 10:31:15