#C572. Minimum Distance to Visit Remaining Checkpoints
Minimum Distance to Visit Remaining Checkpoints
Minimum Distance to Visit Remaining Checkpoints
You are given an integer \(N\) representing the total number of checkpoints numbered from 0 to \(N-1\) arranged on a straight line such that the distance between any two consecutive checkpoints is 1. A robot has visited a subset of these checkpoints. The task is to compute the minimum distance the robot needs to travel in order to visit all the remaining checkpoints. Since each unvisited checkpoint contributes a distance of 1, the answer is given by \(N - m\), where \(m\) is the number of checkpoints already visited.
Input: The first line contains an integer \(N\). The second line contains an integer \(m\) indicating the number of visited checkpoints. The third line contains \(m\) space-separated integers representing the indices of the visited checkpoints.
Output: Print a single integer denoting the minimum distance the robot needs to travel to visit all the remaining checkpoints.
inputFormat
The input is read from standard input (stdin) and consists of three lines:
- The first line contains a single integer \(N\), the total number of checkpoints.
- The second line contains an integer \(m\), the number of checkpoints already visited.
- The third line contains \(m\) space-separated integers representing the visited checkpoints.
outputFormat
Output a single integer to standard output (stdout): the minimum distance the robot needs to travel to visit all unvisited checkpoints.
## sample4
2
0 1
2
</p>