Challenges
Please select a challenge
Problem Statement
A war has started between two rival countries A and B. Country A wants to destroy the Capital city of B through aerial bombing. But due to the sudden outbreak of war, the ammunition reserves are low on both sides. Due to less quantity of ammunation, fighter pilot Jeff has been asked to carry the exact number of bombs that are required to destroy the whole city. Each bomb can be dropped on a building only.
Capital of country B is a one dimensional city with n buildings, where each building (i) is located at some x(i) on the x-axis. Jeff has to destroy every building in the city. Each bomb has a destructive range k, meaning it can destroy everything at a distance ≤ k units away from its point of impact.
Now given a map of the city and the range k of the bomb, Jeff wants you to find the minimum number of bombs he needs to destroy the whole city(each building must be in the destructive range of atleast one bomb).
Input
The first line contains two space-separated integers n(number of buildings in the city) and k(range of destruction of each bomb).
The second line contains n space-separated integers, depicting the location of buildings on the x-axis.
Output
Print a single integer denoting the minimum number of bombs required to destroy the city.
Constraints
1 ≤ n,k ≤ 10^5
1 ≤ x ≤ 10^5
Sample Input
4 2 1 2 3 4
Sample Output
1
Dcoded By: Rajat Gupta
Solved By: 299
Maximum Marks: 15