CF BUDDY
← Problems·

990B · Micro-World

1200 · greedy, sortings

Problem: You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.

You know that you have nn bacteria in the Petri dish and size of the ii-th bacteria is aia_i. Also you know intergalactic positive integer constant KK.

The ii-th bacteria can swallow the jj-th bacteria if and only if ai>aja_i > a_j and aiaj+Ka_i \le a_j + K. The jj-th bacteria disappear, but the ii-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria ii can swallow any bacteria jj if ai>aja_i > a_j and aiaj+Ka_i \le a_j + K. The swallow operations go one after another.

For example, the sequence of bacteria sizes a=[101,53,42,102,101,55,54]a=[101, 53, 42, 102, 101, 55, 54] and K=1K=1. The one of possible sequences of swallows is: [101,53,42,102,101,55,54][101, 53, 42, 102, \underline{101}, 55, 54] \to [101,53,42,102,55,54][101, \underline{53}, 42, 102, 55, 54] \to [101,42,102,55,54][\underline{101}, 42, 102, 55, 54] \to [42,102,55,54][42, 102, 55, \underline{54}] \to [42,102,55][42, 102, 55]. In total there are 33 bacteria remained in the Petri dish.

Since you don't have a microscope, you can only guess, what the minimal possible number of bacteria can remain in your Petri dish when you finally will find any microscope.

Input Format: The first line contains two space separated positive integers nn and KK (1n21051 \le n \le 2 \cdot 10^5, 1K1061 \le K \le 10^6) — number of bacteria and intergalactic constant KK.

The second line contains nn space separated integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1061 \le a_i \le 10^6) — sizes of bacteria you have.

Output Format: Print the only integer — minimal possible number of bacteria can remain.

Note: The first example is clarified in the problem statement.

In the second example an optimal possible sequence of swallows is: [20,15,10,15,20,25][20, 15, 10, 15, \underline{20}, 25] \to [20,15,10,15,25][20, 15, 10, \underline{15}, 25] \to [20,15,10,25][20, 15, \underline{10}, 25] \to [20,15,25][20, \underline{15}, 25] \to [20,25][\underline{20}, 25] \to [25][25].

In the third example no bacteria can swallow any other bacteria.

Sample Cases

Case 1

Input

7 1
101 53 42 102 101 55 54

Output

3

Case 2

Input

6 5
20 15 10 15 20 25

Output

1

Case 3

Input

7 1000000
1 1 1 1 1 1 1

Output

7

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback