#K58117. Minimum Rest Stops

    ID: 30572 Type: Default 1000ms 256MiB

Minimum Rest Stops

Minimum Rest Stops

You are given a hiking trail of length \(L\) and a maximum distance \(M\) that can be covered in one go without a rest. In addition, there are several potential rest stops located at various positions along the trail. Your task is to determine the minimum number of rest stops required in order to complete the hike. Note that you always start at position 0 and your goal is to reach position \(L\).

If it is impossible to reach the destination \(L\) with the given maximum distance \(M\) and available rest stops, output \(-1\). When there are no rest stops provided, the hike is only possible if \(L \leq M\), in which case the answer is 0.

The input provides the trail length \(L\), the maximum distance \(M\), and the number of available rest stops \(N\), followed by \(N\) integers indicating the positions of the rest stops (in any order). The solution should use a greedy strategy.

inputFormat

The first line of input contains two integers \(L\) and \(M\), where \(L\) is the length of the hiking trail and \(M\) is the maximum distance you can travel without stopping.

The second line contains an integer \(N\) representing the number of rest stops available.

If \(N > 0\), the third line contains \(N\) space-separated integers representing the positions of the rest stops. If \(N = 0\), there is no third line.

outputFormat

Output a single integer which is the minimum number of rest stops required to complete the hike. If it is impossible to reach the destination using the available rest stops under the given constraints, output \(-1\).

## sample
10 3
6
4 1 2 6 8 9
4