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. 谈一谈a:link、a:visited、a:hover、a:active的正确使用顺序

    前端路上,未来还远,所以基础部分必须扎实,走好现在脚下的每一步才是现在最重要的. 下面进入正题吧. 1. <a>标签 我们先说一说<a>标签是干啥用的. <a> 标 ...

  2. UNIX C 总结

    --day01--王建立QQ:2529866769今天的内容:一.计算机的框架什么是操作系统?(汽车)加油系统 油门 用户跟加油子系统交互的窗口.(接口)方向系统 方向盘 用户跟方向系统的交互接口.导 ...

  3. PHP基础库及扩展库安装

    一.安装PHP所需的lib库(基础库): 1.yum install zlib-devel libxml2-devel libjpey-devel libjpeg-turbo-devel libico ...

  4. Problem 21

    Problem 21 https://projecteuler.net/problem=21 Let d(n) be defined as the sum of proper divisors of  ...

  5. 基于Python3.7和opencv的人脸识别(含数据收集,模型训练)

    前言 第一次写博客,有点紧张和兴奋.废话不多说,直接进入正题.如果你渴望使你的电脑能够进行人脸识别:如果你不想了解什么c++.底层算法:如果你也不想买什么树莓派,安装什么几个G的opencv:如果你和 ...

  6. Industrial Nim

    http://codeforces.com/contest/15/problem/C 题意: 现有n个采石场,第i个采石场有mi堆石子 各堆分别有xi,xi+1……,xi+m-1颗石子 两名选手使用最 ...

  7. extjs 4 chart 时间轴格式的处理

    var dayStore = Ext.create('Ext.data.JsonStore', { fields: [{ name: 'name', type: 'date', dateFormat: ...

  8. 在ANGULAR的SERVICE中,哪种才是最基本的实现?(Provider)

    今天刚好看到这一节. 节选一下,稍后,实操完成之后,会补上所有代码 Sometimes, it might be interesting to create configurable services ...

  9. BlockQueue中ArrayBlockingQueue和LinkedBlockingQueue比较

    LinkedBlockingQueue是BlockingQueue的一种使用Link List的实现,它对头和尾(取和添加操作)采用两把不同的锁,相对于ArrayBlockingQueue提高了吞吐量 ...

  10. Retrofit网络框架入门使用

    1.简单介绍 retrofit事实上就是对okhttp做了进一步一层封装优化. 我们仅仅须要通过简单的配置就能使用retrofit来进行网络请求了. Retrofit能够直接返回Bean对象,比如假设 ...