#P11885. Island Hopping with Limited Jumps
Island Hopping with Limited Jumps
Island Hopping with Limited Jumps
You are given islands numbered from to . In addition, you are given a sequence of positive integers of length . When you are on island (with ), you can jump either to island or to island (note that ).
You are also given a positive integer . For each island , define $$f(i,k)$$ as the number of distinct islands that can be reached from island by performing at most jumps (including the starting island itself).
It is guaranteed that the sequence satisfies the following special property: for any , either $$v_i \le j$$ or $$v_j \le v_i$$.
For each island , compute $$f(i,k)$$.
Note: Even if there are multiple ways to reach an island within jumps, that island is only counted once. Also, observe that since the jumps are only in the forward direction, the set of reachable islands will always form a contiguous segment of islands.
inputFormat
The first line contains two positive integers and , where is the number of islands and is the maximum number of jumps allowed.
The second line contains positive integers: .
outputFormat
Output integers. The -th integer should be equal to $$f(i,k)$$, the number of distinct islands that can be reached from island using at most jumps. The answers should be printed in order from island to island , separated by spaces.
sample
5 2
3 3 5 5
5 4 3 2 1