PinterestOA #7
Travel Distance on Scooters
Estimated EasyJudge-ready
Topics (AI-labelled)Simulation
The street runs from 0 to finish. When you are at position p, walk to the nearest scooter at a position not less than p; if there is none, walk to the finish. Ride that scooter to the farthest position its battery can reach (at most 10 units to the right), and repeat if you have not reached the finish yet. Return the total distance ridden.
Input
The first line contains finish and n; the second line contains n distinct integer positions. Source constraints: finish≤1000, and the positions are distinct integers on the street; this site explicitly defines the street range as [0,finish], so n≤finish+1.
Output
Output one integer: the total distance traveled on all scooters; walking distance is not counted.
Example 1
Input:
23 3
7 4 14
Output:
19
Example 2
Input:
27 4
15 7 3 10
Output:
20
Example 3
Input:
10 0
Output:
0
Editorial
Loading solution…