#P4909. [USACO06MAR] Ski Lift G
[USACO06MAR] Ski Lift G
Description
The mountains of Colorado are represented as a polyline in the 2D plane. This polyline has endpoints and segments. The -th endpoint has x-coordinate and y-coordinate . The y-coordinate represents altitude (elevation).
Ron plans to build a ski resort for the cows, and needs to plan a ski lift line along the mountains. The cable line is also a polyline, composed of several cable segments, starting at the first mountain endpoint and ending at the last endpoint. Each cable segment can either follow the outline of the mountain or be suspended in the air, skipping several endpoints with lower altitude. The horizontal span of each cable segment is limited and cannot exceed the given integer . Ron must build pillars at the endpoints of each cable segment to fasten the cable.
Please help him plan which mountain endpoints should have pillars so that the number of pillars is minimized. Note that, by the problem statement, the start and end endpoints must have pillars.
Constraints , , .
Input Format
The first line contains two integers and .
Lines through : line contains an integer .
Output Format
Output a single integer, the minimum number of pillars required.
13 4
0
1
0
2
4
6
8
6
8
8
9
11
12
5
Hint
Explanation: The optimal plan is to place pillars at . cannot directly connect to because the altitude at is higher; cannot directly connect to because the span exceeds .
Translated by ChatGPT 5
京公网安备 11011102002149号