cswork / OA打开练习工作台

PinterestOA #7

Travel Distance on Scooters

估计简单可在线判题

考点(AI 标注)模拟/实现

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.

输入格式

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 one integer: the total distance traveled on all scooters; walking distance is not counted.

样例 1

输入:

23 3
7 4 14

输出:

19

样例 2

输入:

27 4
15 7 3 10

输出:

20

样例 3

输入:

10 0

输出:

0