Flying Squirrel
Time limit3sMemory limit1024 MB
Find the minimum climbing cost for a squirrel to cross all pillars from height L on the first to height R on the last, never touching the ground.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Segment tree, Stack
- Solved
- No attempts yet
Problem
There are pillars in a row on a two-dimensional plane. The pillars are numbered from 1 to from left to right.
The base of the -th pillar () is at the point , and its height is . So the pillar is the line segment connecting and . Also, .
At the start, the flying squirrel is at height on the leftmost pillar, that is, at the point . The squirrel wants to pass through all pillars in order from left to right and reach height on the rightmost pillar, that is, the point .
When the squirrel flies from one pillar to the next, if it moves () to the right, its height decreases by . It must not touch the ground before it reaches the next pillar. Arriving at height 0 on the next pillar is allowed.
On a pillar, the squirrel can climb up or move down. It cannot climb above the height of the pillar. Climbing up by () on the -th pillar costs . Moving down costs nothing.
Figure 1 shows one possible route of the squirrel.

Figure 1
The route on the left of Figure 2 is not allowed, because the squirrel touches the ground along the way. The route on the right of Figure 2 is also not allowed, because it skips some of the pillars.

Figure 2
Compute the minimum total cost for the squirrel to reach the target position.