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. Js—innerHTML和innerText的区别

    1.innerHTML属性和innerText属性 都是对元素的一个操作,简单讲,innerHTML可以在某种特定环境下重构某个元素节点的DOM结构,innerText只能修改文本值 在JavaScr ...

  2. jquery操作元素之间相邻的元素的获取方式

    <!DOCTYPE html><html> <head> <style> .siblings * { display: block; border: 2 ...

  3. vmware 15安装破解及使用教程

    VMware Workstation Pro15虚拟机破解版(序列号+安装教程) VMware15已经推出,根据版本号名为VMware Workstation Pro 15是一款强大好用的桌面虚拟机软 ...

  4. PHP面试:说下什么是堆和堆排序?

    堆是什么? 堆是基于树抽象数据类型的一种特殊的数据结构,用于许多算法和数据结构中.一个常见的例子就是优先队列,还有排序算法之一的堆排序.这篇文章我们将讨论堆的属性.不同类型的堆以及堆的常见操作.另外我 ...

  5. Django——5 自定义过滤器及标签

    Django 自定义过滤器 自定义标签 简单标签 包含标签 自定义过滤器 自定义过滤器就是一个带有一个或两个参数的Python 函数: - (输入的)变量的值 —— 不一定是字符串形式. - 参数的值 ...

  6. Jquery书写ajax

    根据API学习本章 Jquery书写ajax 使用ajax发送表单到servlet,发送时显示等待图片,servlet处理完返回信息,在页面显示返回信息,并且隐藏等待图片 <%@ page la ...

  7. MYSQL 字符集 MYSQL 源码

    http://blog.csdn.net/maray/article/details/46504621

  8. [转]十五天精通WCF——第六天 你必须要了解的3种通信模式

    wcf已经说到第六天了,居然还没有说到这玩意有几种通信模式,惭愧惭愧,不过很简单啦,单向,请求-响应,双工模式,其中的第二种“请求-响应“ 模式,这个大家不用动脑子都清楚,这一篇我大概来分析下. 一: ...

  9. CF #EDU R1 E

    最二的一次了~我开始以为是带有贪心的DP,谁知道想错了.后来才想明白,暴力二分+记忆化DP #include <iostream> #include <cstdio> #inc ...

  10. CF #324 DIV2 C题

    #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...