Problem list
Log in
#r03243 · Online Judge > GoldOJ

Farthest Nearby House

Bronze I 2.0 s 1024 MB

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
Source
Online Judge > GoldOJ
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code