← 返回 coinbase 的题目列表Drone Food Delivery With Charging Stations: Simulate Forward Nearest Station and Compute Total Distance
类型:online_judge
Drone Food Delivery: Simulate “Nearest Forward Station” and Compute Total Distance
You need to simulate a drone delivery system that moves a package from position 0 to target. All positions lie on a straight line.
Given:
Integer target (target > 0)
Integer array stations, the positions of charging stations
Rules
The drone can only take off from a charging station.
Each flight can move forward by at most 10 units.
After the flight, the drone lands and the package position becomes the landing position.
Process (repeat until reaching target)
At each round, let the current package position be current:
Find the nearest forward charging station s such that s >= current and s is minimal among such stations.
A human manually carries the package from current to s.
Launch the drone from s, fly forward by at most 10, and land at some position land.
Update current = land.
Stop when current >= target.
Task
Compute and return the total distance incurred by the above process.
Note: The phrase “then compute distance” is ambiguous. Confirm with the interviewer whether to count only the manual carrying distance, or the sum of manual carrying distance plus drone flight distance.
Example (for understanding)
target = 25
stations = [0, 7, 15]
From current=0: nearest station is 0, carry 0; drone flies to 10; current=10. From current=10: nearest station is 15, carry 5; drone flies to 25; done.
Output the required “total distance” per the interviewer's definition.
Example
Input
25
3
0 7 15
Output
5