A package must be delivered on a one-dimensional line from position 0 to position target.
You are given an array stations, where each element is the position of a charging station.
A drone can only take off from a charging station, and each flight can move the package forward by at most 10 units. After the drone lands, the package's position becomes the landing position.
The delivery process is fixed and repeats until the package reaches target:
-
Let
current
be the package's current position.
-
Find the nearest charging station at or ahead of
current
, meaning the minimum station position
s
such that
s >= current
.
-
A human carries the package from
current
to
s
. This adds
s - current
to the manual carrying distance.
-
The drone launches from
s
and flies forward as far as possible, up to
10
units, without passing the target. The new package position becomes
min(s + 10, target)
.
Return the total distance the package is carried manually.
You may assume the process is always feasible. If stations is not sorted, your algorithm should handle that.