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 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 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 (1≤n≤2⋅10^5, 1≤K≤10^6) — number of bacteria and intergalactic constant K.

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

解题思路:题目的意思就是只要ai>aj且ai-aj<=K,aj就可以被吞噬掉(标记为-1)。做法:先排序;然后用两个变量模拟指针i,j指向当前元素的位置,初始值都为0。如果a[j]-a[i]==0,j后移一位,即j++;如果a[j]-a[i]>k,i就往后移一位,即i++;否则(a[j]-a[i]<=K)将a[i]标记为-1,然后i++;最后统计数组a中值不是-1的个数,即为最小剩余细菌的个数,水过。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+;
int n,k,i,j,m,tmp,a[maxn];
int main(){
cin>>n>>k;m=i=j=;
for(int p=;p<n;++p)cin>>a[p];
sort(a,a+n);
while(i<n&&j<n){
tmp=a[j]-a[i];
if(tmp==)j++;
else if(tmp>k)i++;
else{a[i]=-;i++;}
}
for(int p=;p<n;++p)
if(a[p]!=-)m++;
cout<<m<<endl;
return ;
}

F - Micro-World(简单模拟)的更多相关文章

  1. java web学习总结(二十二) -------------------简单模拟SpringMVC

    在Spring MVC中,将一个普通的java类标注上Controller注解之后,再将类中的方法使用RequestMapping注解标注,那么这个普通的java类就够处理Web请求,示例代码如下: ...

  2. (hdu step 8.1.6)士兵队列训练问题(数据结构,简单模拟——第一次每2个去掉1个,第二次每3个去掉1个.知道队伍中的人数&lt;=3,输出剩下的人 )

    题目: 士兵队列训练问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

  3. python--selenium简单模拟百度搜索点击器

    python--selenium简单模拟百度搜索点击器 发布时间:2018-02-28 来源:网络 上传者:用户 关键字: selenium 模拟 简单 点击 搜索 百度 发表文章摘要:用途:简单模拟 ...

  4. 简单模拟Java中反射的应用场景

    有人说Java是一门静态语言.那么何为静态语言,动态语言又是什么? 1.动态语言 是一类在运行时可以改变其结构的语言:例如新的函数.对象.甚至代码可以 被引进,已有的函数可以被删除或是其他结构上的变化 ...

  5. WPF简单模拟QQ登录背景动画

    介绍 之所以说是简单模拟,是因为我不知道QQ登录背景动画是怎么实现的.这里是通过一些办法把它简化了,做成了类似的效果 效果图 大体思路 首先把背景看成是一个4行8列的点的阵距,X轴Y轴都是距离70.把 ...

  6. F#之旅3 - F# PK C#:简单的求和

    原文链接:https://swlaschin.gitbooks.io/fsharpforfunandprofit/content/posts/fvsc-sum-of-squares.html Comp ...

  7. Linux 内核 链表 的简单模拟(2)

    接上一篇Linux 内核 链表 的简单模拟(1) 第五章:Linux内核链表的遍历 /** * list_for_each - iterate over a list * @pos: the & ...

  8. Linux 内核 链表 的简单模拟(1)

    第零章:扯扯淡 出一个有意思的题目:用一个宏定义FIND求一个结构体struct里某个变量相对struc的编移量,如 struct student { int a; //FIND(struct stu ...

  9. JavaWeb学习总结(四十九)——简单模拟Sping MVC

    在Spring MVC中,将一个普通的java类标注上Controller注解之后,再将类中的方法使用RequestMapping注解标注,那么这个普通的java类就够处理Web请求,示例代码如下: ...

随机推荐

  1. PAT_A1018#Public Bike Management

    Source: PAT A1018 Public Bike Management (30 分) Description: There is a public bike service in Hangz ...

  2. mybatis批量操作(foreach)

    foreach可以在SQL语句中通过拼接的方式进行集合迭代.foreach元素的属性主要有collection,item,index,separator,open,close. item属性:表示循环 ...

  3. 集成学习_Bagging 和随机森林(rf)

       集成学习方式总共有3种:bagging-(RF).boosting-(GBDT/Adaboost/XGBOOST).stacking      下面将对Bagging 进行介绍:(如下图所示) ...

  4. numpy.tile()

    numpy.tile()是个什么函数呢,说白了,就是把数组沿各个方向复制 比如 a = np.array([0,1,2]),    np.tile(a,(2,1))就是把a先沿x轴(就这样称呼吧)复制 ...

  5. 基于jquery的常见函数封装

    /// <reference path="jquery-1.8.0.min.js" />/** DIV或元素居中* @return*/jQuery.fn.mCenter ...

  6. 原型链、构造函数、箭头函数、se6数组去重

    原型链 例子如下: var arr = [1, 2, 3]; 其原型链为:arr ----> Array.prototype ----> Object.prototype ----> ...

  7. 【微软2017年预科生计划在线编程笔试 A】Legendary Items

    [题目链接]:https://hihocoder.com/problemset/problem/1489 [题意] 每轮游戏; 你一开始有p的概率获得超神标记; 如果这轮游戏你没获得超神标记; 那么你 ...

  8. Java基础学习总结(74)——Java常见笔试题及答案汇总

    1. 下面哪些是合法的标识符?(ABE )--标识符 A. $persons B. TwoUsers C. *point D. this E. _endline 2. 下面程序运行的结果是( D )- ...

  9. 重庆OI2017 老 C 的任务

    老 C 的任务 时间限制: 2 Sec  内存限制: 512 MB 题目描述 老 C 是个程序员. 最近老 C 从老板那里接到了一个任务——给城市中的手机基站写个管理系统.作为经验丰富的程序员,老 C ...

  10. 【ACM】nyoj_14_会场安排问题_201308151955

    会场安排问题时间限制:3000 ms  |  内存限制:65535 KB 难度:4描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工作就是安 ...