#P11388. Flower Jump
Flower Jump
Flower Jump
You are given \( n \) flowers and a positive integer \( k \). The height of the \( i\)-th flower is \( a_i \). Initially, Filip stands on the first flower.
When Filip is on the \( i \)-th flower, she can jump to the \( j \)-th flower if and only if:
- \( i < j \), and
- \( |a_i - a_j| \le k \).
Your task is to determine which flowers are reachable by Filip via one or more valid jumps. Output a sequence of \( n \) numbers: for each flower, print 1
if it is reachable, and 0
otherwise.
inputFormat
The first line contains two integers \( n \) and \( k \) separated by a space.
The second line contains \( n \) integers \( a_1, a_2, \dots, a_n \) representing the heights of the flowers.
outputFormat
Output a single line containing \( n \) space-separated integers. The \( i \)-th integer should be 1
if the \( i \)-th flower is reachable from the first one using valid jumps, and 0
otherwise.
sample
5 3
1 4 2 7 4
1 1 1 1 1
</p>