The Little Bird
Time limit2sMemory limit256 MB
A bird jumps from tree 1 to tree n in flights of at most k and minimizes landings on trees at least as tall as the takeoff tree.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Stack, Segment tree
- Solved
- No attempts yet
Problem
Behind Gyeonggi Science High School there is a forest of trees standing in a row. On the first tree sits a little bird that wants to get to the top of the last tree. The bird is very small, so a single flight covers a limited distance. If the bird is on tree , one flight takes it to one of the trees , and it cannot reach any tree farther away than that.
Climbing to a taller tree costs the little bird more effort than dropping to a shorter one. The bird feels tired whenever it flies to a tree whose height is equal to or greater than the height of the tree it is sitting on.
The bird wants to reach the last tree while feeling tired as few times as possible. Other birds in the same forest want to reach the last tree with the same minimum amount of tiredness, and their values of can differ. For every bird, find the minimum number of times it feels tired.
Input
The first line contains an integer (), the number of trees.
The second line contains the integers (). Here is the height of tree .
The third line contains the number of birds () that want to fly to the last tree.
Line of the following lines contains (), the distance bird covers in one flight.
Output
Print the answers on lines. Line contains the minimum number of times bird feels tired on its way to the last tree.
Hint
In the first example the bird with visits trees 1, 3, 5, 7, 8, 9 in that order. It feels tired flying from tree 3 to tree 5 and from tree 7 to tree 8, so twice in total.