Overshadowed Trees
Time limit1sMemory limit1024 MB
For each tree, check whether any taller tree within K positions exceeds its height by at least M, and list all such trees.
- Level
Medium4 of 10
- Topics
- Sliding window, Array, Brute force, Implementation
- Solved
- No attempts yet
Problem
Forester Linas takes care of a forest with trees. All the trees are planted on a single straight line, and the distance between any two adjacent trees is always 1 meter.
Linas dislikes that some trees are "overshadowed" by others, so he wants to fertilize the overshadowed trees to help them grow better. The -th tree is overshadowed if the tallest other tree growing within a radius of meters around it is taller than its own height by at least .
For example, consider , , with tree heights in order.

- Tree 5 is overshadowed. Within distance there are two trees (tree 4 and tree 6). The difference between the taller tree 4's height () and tree 5's height () is , which is at least .
- Tree 6 is not overshadowed. Within distance there is only tree 5. The difference between their heights is , which is not at least .
Find all overshadowed trees.
Input
The first line contains three space-separated integers , , and : the number of trees, the radius Linas inspects, and the height-difference threshold, respectively.
The second line contains space-separated integers , the heights of the trees.
Output
On the first line, print a single integer: the number of overshadowed trees in Linas's forest. On the second line, print the numbers of the overshadowed trees in increasing order (from the smallest to the largest), separated by spaces. If there are no overshadowed trees, print on the first line and leave the second line empty.
Constraints
- ()