P1610 Lights in Hongshan Cave
Description
There are $n$ lamps with positions $p_i$, and all $p_i$ are distinct. When the distance between two lamps is less than $dist$, if there is still a lamp that remains on within this safety distance, you may turn off those lamps (that is, if the distance between the $(i-1)$-th and $(i+1)$-th lamps is $\leq dist$, then the $i$-th lamp can be turned off).
While ensuring that the cave remains sufficiently illuminated, find the maximum number of lamps that can be removed within a single contiguous interval.
The lamps nearest to and farthest from the cave entrance must remain on.
Input Format
The first line contains two numbers, $n$ and $dist$.
The second line contains $n$ numbers, the positions $p_i$ of each lamp.
Output Format
Output one number: the maximum number of lamps that can be removed within a single interval.
Explanation/Hint
For $100\%$ of the testdata, $1 \leq n \leq 10^5$, and $dist$ is guaranteed to be within the range of `int`.
Translated by ChatGPT 5