← 返回 bytedance 的题目列表Walking with Boost Stations (Greedy Simulation)
类型:online_judge
Problem: Total Walking Distance with Boost Stations
Start at position 0 and deliver goods to target on a 1D line. There are m station positions p[i].
Rules:
You may walk from current goods position cur to a station p[i] (must satisfy p[i] >= cur). This walking distance adds to the total.
After reaching that station, a drone boosts the goods forward by a fixed distance d, updating cur = p[i] + d.
Repeat until cur >= target.
If at some point cur < target and no station with p[i] >= cur exists, you must walk directly to target.
Compute the total walking distance.
Input (one common OA format)
Line 1: m target d
Line 2: m integers p[i]
Output
One integer: total walking distance.
Example
Input
3 25 10
0 10 20
Output
0