Houses sit on a line at integer positions. Two houses are 'nearby' if their distance is at most $K$. For each house, print the distance to the farthest house that is still nearby, or -1 if it has no nearby house. Print the answers in input order.
Input
Line 1: $N$ $K$ ($2 \le N \le 100$). Line 2: the $N$ positions ($1 \le p_i \le 10^9$).
Output
Print each house's answer, space-separated.
Example 1
Input
6 6 1 3 7 9 13 20
Output
6 6 6 6 6 -1
Example 2
Input
5 4 10 1 6 14 3
Output
4 2 4 4 3
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.