CB Open 2024 Problem 2 - Nikola and the Teslas


Submit solution

Points: 7
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Nikola Tesla is a fan of Royale Clash and he loves to use the tesla card in the game. However, he has been 3-crowned several times and is now questioning whether he is positioning his teslas effectively.

Positioning a tesla can be challenging as it requires finding the right balance between being close enough to damage enemy troops and far enough to avoid destruction.

To improve his positioning skills, Nikola has devised simple exercise. He has \(N\) enemies positioned on the number line, with the \(i\)-th enemy being located at an integer position \(P_i\). Nikola wants to determine the minimum number of teslas with a radius of \(R\) that he needs to be able to hit all \(N\) enemies with at least one tesla.

Teslas are very expensive. Hence, they must be placed on integer locations, so that they can be subsidized.

Constraints

\(1 \le N \le 10^5\)

\(1 \le R \le 10^9\)

\(1 \le P_i \le 10^9\)

Input Specification

The first line will contain two integers \(N\) and \(R\), the number of enemies and the radius of the tesla towers, respectively.

The next line will contain \(N\) space-separated integers, \(P_i\), the position of the \(i\)-th enemy.

Output Specification

Output the minimum number of teslas Nikola needs to be able to hit all the enemy troops.

Sample Input 1

5 1
3 7 5 8 10

Sample Output 1

3

Explanation

You can place teslas at position \(4\), \(8\), and \(10\) to cover all the enemies. It can be shown it is impossible using less than \(3\) teslas.


Comments

There are no comments at the moment.