Leapcow
InterviewTime limit1sMemory limit1024 MB
Find the fewest leaps of length 1 to L needed to go from 0 to E on a number line without landing on any of the buried cow positions.
- Level
Easy3 of 10
- Topics
- Dynamic programming, Array
- Solved
- No attempts yet
Problem
Cows like to bury each other in sand at the beach. On this beach, cows are buried only at integer coordinates of a one-dimensional number line. Bessie wants to travel from one end of the beach (coordinate 0) to the other end (coordinate ) without stepping on any buried cow.
Bessie travels only by leaps, and each leap has a length from 1 to .
You are given the locations (from 1 to ) of the buried cows, where . Find the least number of leaps Bessie needs to get from one end to the other. An answer is guaranteed to exist.
Input
The first line contains three space-separated integers , , and . Each of the next lines contains one integer, the coordinate of a buried cow.
Output
Print a single integer: the smallest number of legal leaps Bessie needs to reach coordinate .
Hint
The diagram shows the beach and the leaps. The letter c marks a cow.
# # c c # # <--- cow denoted by 'c'
0 1 2 3 4 5 <--- location numbers
1 2 3 <--- where leaps 1, 2, and 3 end