Micro-World

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 ai≤aj+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 ai≤aj+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 3 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 (1≤n≤2⋅105, 1≤K≤106) — number of bacteria and intergalactic constant K.

The second line contains n space separated integers a1,a2,…,an (1≤ai≤106) — 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.

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
LL a[300010];
int main(){
     LL m, n, i, j, l;
          while(scanf("%lld%lld",&n, &m) != EOF)
     {
         map<int, int> mp;
         memset (a, 0, sizeof(a));
         for (i = 0; i < n; i ++)
         {
             scanf("%lld", &a[i]);
             mp[a[i]] ++;
         }
                  sort(a, a + n);
                  l = unique(a, a + n) - a;
         for (i = 1 ; i < l; i ++)
         {
             if(a[i] > a[i-1] && a[i-1] + m >= a[i])
             {
                 n = n - mp[a[i-1]];
             }
         }
         printf("%lld\n", n);
     }
          return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值