Jumping Around
time limit per test: 5 seconds
memory limit per test: 256 megabytes
Articles
There is an infinite pond that can be represented with a number line. There are n rocks in the pond, numbered from to . The -th rock is located at an integer coordinate . The coordinates of the rocks are pairwise distinct. The rocks are numbered in the increasing order of the coordinate, so .
A robot frog sits on the rock number . The frog is programmable. It has a base jumping distance parameter . There also is a setting for the jumping distance range. If the jumping distance range is set to some integer , then the frog can jump from some rock to any rock at a distance from to inclusive in any direction. The distance between two rocks is an absolute difference between their coordinates.
You are assigned a task to implement a feature for the frog. Given two integers and determine if the frog can reach a rock number from a rock number performing a sequence of jumps with the jumping distance range set to . The sequence can be arbitrarily long or empty.
You will be given testcases for that feature, the -th testcase consists of two integers and . Print “Yes” if the i-th rock is reachable and “No” otherwise.
You can output “YES” and “NO” in any case (for example, strings “yEs”, “yes”, “Yes” and ‘YES"’ will be recognized as a positive answer).
Input
The first line contains four integers , , and — the number of rocks, the number of testcases, the starting rock and the base jumping distance parameter.
The second line contains integers — the coordinates of the rocks. The coordinates of the rocks are pairwise distinct. The rocks are numbered in the increasing order of distance from the land, so .
Each of the next lines contains two integers and — the parameters to the testcase.
Output
For each of the testcases print an answer. If there is a sequence of jumps from a rock number to a rock number with the jumping distance range set to , then print “Yes”. Otherwise, print “No”.
Examples
input
1 | 7 4 4 5 |
output
1 | Yes |
input
1 | 10 8 6 11 |
output
1 | Yes |
input
1 | 6 9 6 6 |
output
1 | Yes |
input
1 | 4 1 1 10 |
output
1 | Yes |
Note
Explanation of the first example:
In the first testcase the destination rock is the same as the starting rock, thus no jumps are required to reach it.
In the second testcase the frog can jump any distance in the range . Thus, it can reach rock number (by jumping to the right) and rock number (by jumping to the left). From rock number it can reach rock number (by jumping to the left). From rock number it can reach rock number (by jumping to the left). However, there is no way to reach rock number .
In the third testcase the frog can jump any distance in the range . Thus, it can reach rock number by jumping to rock first and to afterwards.
The fourth testcase is shown in the explanation for the second testcase.
Tutorial
Code
1 |
|