Baby
Limits: 2 sec., 512 MiB
This statement was translated automatically from Ukrainian.
Zenyk and Marichka recently had a baby. One evening, Zenyk noticed that their baby loves playing with toy trucks. He places \(n\) trucks on a straight road at points with coordinates \(A_1, A_2, \dots, A_n\). Also, on the same road, he defines \(n\) target points: \(B_1, B_2, \dots, B_n\).
The baby can move each truck in any direction by a distance of \(\le d\). Check if the trucks can finish their movement such that there is at least one truck at each target point?
Input
The first line contains two numbers \(n\) — the number of trucks and targets, and \(d\) — the distance each car can move.
The second line contains \(n\) positive integers sorted in ascending order \(A_i\) — the coordinates of the trucks. The third line contains \(n\) positive integers sorted in ascending order \(B_i\) — the coordinates of the targets.
Output
Print YES, if the trucks can finish their movement such
that every target point has at least one truck, or NO if
this result cannot be achieved.
Constraints
\(1 \le n \le 10^5\),
\(1 \le A_i, B_i, d\le 10^9\),
\(A_i \le A_{i+1}\), \(B_i \le B_{i+1}\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 7 4 4 4 8 11 13 14 17 4 7 8 11 12 15 17 | YES |
| Input (stdin) | Output (stdout) |
|---|---|
| 2 4 1 11 5 6 | NO |
Notes
The image shows one of the possible movements of the trucks so that they all reach their targets.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|