Skokovi
InterviewTime limit5sMemory limit1024 MB
Given flower heights and a limit K, mark which flowers a grasshopper can reach from the first one by jumping only rightward to flowers whose height differs by at most K.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Segment tree
- Solved
- No attempts yet
Problem
In a land who knows where, in a world who knows when, lives a bee named Maya. Her adventure-filled life is an endless source of ideas for tasks, so we chose one of them. Maya's friend, a grasshopper named Filip, is preparing for the Olympics in flower jumping. The meadow has flowers in a row, and flower has height , a positive integer. Filip always jumps from left to right. From flower , he can jump to flower if and only if and , where is a given positive integer. Starting from the leftmost flower, determine which flowers Filip can reach.
Input
The first line contains positive integers () and (). The second line contains positive integers (), the heights of the flowers.
Output
Print numbers, each either or , on a single line. The -th number is if flower is reachable and otherwise. The first flower is always reachable, since Filip starts there.