F - Micro-World

Problem description

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 n bacteria in the Petri dish and size of the i-th bacteria is ai. Also you know intergalactic positive integer constant K.

The i-th bacteria can swallow the j-th bacteria if and only if ai>aj and aiaj+K. The j-th bacteria disappear, but the i-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria i can swallow any bacteria j if ai>aj and aiaj+K. The swallow operations go one after another.For example, the sequence of bacteria sizes a=[101,53,42,102,101,55,54] and K=1. The one of possible sequences of swallows is: [101,53,42,102,101,55,54] [101,53,42,102,55,54] [101,42,102,55,54] [42,102,55,54]→ [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

The first line contains two space separated positive integers n and K (1n210^51K10^6) — number of bacteria and intergalactic constant K.

The second line contains nn space separated integers a1,a2,,an (1ai10^6) — sizes of bacteria you have.

Output

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

Examples

Input
7 1
101 53 42 102 101 55 54
Output
3
Input
6 5
20 15 10 15 20 25
Output
1
Input
7 1000000
1 1 1 1 1 1 1
Output
7

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,25] [20,15,10,25] [20,15,25]  [20,25] [25].In the third example no bacteria can swallow any other bacteria.

解题思路:

AC代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn=2e5+5;
 4 int n,k,i,j,m,tmp,a[maxn];
 5 int main(){
 6     cin>>n>>k;m=i=j=0;
 7     for(int p=0;p<n;++p)cin>>a[p];
 8     sort(a,a+n);
 9     while(i<n&&j<n){
10         tmp=a[j]-a[i];
11         if(tmp==0)j++;
12         else if(tmp>k)i++;
13         else{a[i]=-1;i++;}
14     }
15     for(int p=0;p<n;++p)
16         if(a[p]!=-1)m++;
17     cout<<m<<endl;
18     return 0;
19 }

猜你喜欢

转载自www.cnblogs.com/acgoto/p/9200862.html
F
今日推荐