#K65122. Minimum Camera Positions for Exhibit Photography
Minimum Camera Positions for Exhibit Photography
Minimum Camera Positions for Exhibit Photography
Lara is planning to take pictures of exhibits along a long corridor. Each exhibit is located at a specific position along the corridor. Lara has a camera with a fixed range, which means she can capture any exhibit that lies within a distance r from her standing point.
Your task is to help Lara determine the minimum number of positions she needs to stand at so that all exhibits are photographed. You are given the number of exhibits n, the camera range r, and the positions of the exhibits. Note that the position of each exhibit is given as an integer, and multiple exhibits can have the same position. The corridor can be thought of as a number line.
Hint: To solve this problem, you may need to first sort the positions, then use a greedy strategy to cover as many exhibits as possible from a single standing position.
All mathematical expressions should be formatted in LaTeX if needed. For example, the range condition can be written as: \( |x - p| \leq r \), where \(x\) is the position of an exhibit and \(p\) is Lara's standing position.
inputFormat
The first line of input contains two integers n and r separated by a space, where \( n \) is the number of exhibits and \( r \) is the camera range. The second line contains \( n \) integers separated by spaces, representing the positions of the exhibits along the corridor.
Example:
5 2 1 2 3 5 6
outputFormat
Output a single integer: the minimum number of positions Lara must stand at to cover all exhibits.
## sample5 2
1 2 3 5 6
2
</p>