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 nn bacteria in the Petri dish and size of the ii-th bacteria is aiai. Also you know intergalactic positive integer constant KK.

The ii-th bacteria can swallow the jj-th bacteria if and only if ai>ajai>aj and ai≤aj+Kai≤aj+K. The jj-th bacteria disappear, but the ii-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria ii can swallow any bacteria jj if ai>ajai>aj and ai≤aj+Kai≤aj+K. The swallow operations go one after another.

For example, the sequence of bacteria sizes a=[101,53,42,102,101,55,54]a=[101,53,42,102,101,55,54] and K=1K=1. The one of possible sequences of swallows is: [101,53,42,102,101−−−,55,54][101,53,42,102,101_,55,54] →→ [101,53−−,42,102,55,54][101,53_,42,102,55,54] →→ [101−−−,42,102,55,54][101_,42,102,55,54] →→ [42,102,55,54−−][42,102,55,54_] →→ [42,102,55][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 nn and KK (1≤n≤2⋅1051≤n≤2⋅105, 1≤K≤1061≤K≤106) — number of bacteria and intergalactic constant KK.

The second line contains nn space separated integers a1,a2,…,ana1,a2,…,an (1≤ai≤1061≤ai≤106) — sizes of bacteria you have.

Output

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

Sample Input

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

Hint

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,20_,25] →→ [20,15,10,15−−,25][20,15,10,15_,25] →→ [20,15,10−−,25][20,15,10_,25] →→ [20,15−−,25][20,15_,25] →→ [20−−,25][20_,25] →→ [25][25].

In the third example no bacteria can swallow any other bacteria.

题意:满足题中所给条件的病菌会发生吞并,问最后剩下的病菌的最少的数量。

吞并的条件有两个,可以通过在先确定一个条件的前提下,判断另一个条件。

先对病菌从大到小排一遍序,然后从后向前遍历一遍,只需要判断相邻的两个是否满足条件即可(特殊的是,有相等的数的时候),因为相邻的两个是差最小的,最容易满足第二个条件。

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
const double e=exp();
const int N = ; #define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r map<LL,LL> mp;
LL con[N]; bool cmp(LL a,LL b)
{
return a>b;
}
int main()
{
LL i,p,j,x;
LL n,k;
scanf("%lld%lld",&n,&k);
for(i=;i<n;i++)
{
scanf("%lld",&con[i]);
mp[con[i]]++;
}
sort(con,con+n,cmp);
p=n;
for(i=n-;i>=;i--)
{
if(con[i]>con[i+]&&con[i]<=(con[i+]+k))
{
p=p-mp[con[i+]];
}
}
printf("%lld\n",p);
return ;
}

CodeForces 990B的更多相关文章

  1. CodeForces 990B Micro-World(思维、STL)

    http://codeforces.com/problemset/problem/990/B 题意: 有n个细菌,每个细菌的尺寸为ai,现在有以常数k,如果细菌i的尺寸ai大于细菌j的尺寸aj,并且a ...

  2. Codeforces 990B :Micro-World

    B. Micro-World time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. WPF/MVVM快速指引

    简介 最近微软推出了UWA,又是一波新的C#+xaml学习热.好多小伙伴都对MVVM感觉很好奇,但是有些地方也有点难以理解.特意写了这边文章,希望对你有帮助. 这边文章会很长,所以我会用几个例子的形式 ...

  2. apache 部署web.py

    一.安装Mod_wsgi 1.先yum -y install httpd-devel,否则会提示没有apxs 2.如果在make时 wsgi报错apxs:Error: Command failed w ...

  3. 使用ASP.NET Identity 实现WebAPI接口的Oauth身份验证

    使用ASP.NET Identity 实现WebAPI接口的Oauth身份验证   目前WEB 前后端分离的开发模式比较流行,之前做过的几个小项目也都是前后分离的模式,后端使用asp.net weba ...

  4. mysql中约束

    约束 什么叫做约束? 约束,就是要求数据需要满足什么条件的一种“规定”. 主要有如下几种约束: 主键约束:形式: primary key ( 字段名); 含义(作用):使该设定字段的值可以用于“唯一确 ...

  5. apache常用的两种工作模式 prefork和worker

    apache作为现今web服务器用的最广泛也是最稳定的开源服务器软件,其工作模式有许多中,目前主要有两种模式:prefork模式和worker模式 一.两种模式 prefork模式: prefork是 ...

  6. HDU4681_String

    这个题目是这样的. 给你三个字符串A,B,C,(C一定是A和B的一个公共子序列). 现在要求你构造出一个串D,使得D同时为A和B的子序列,且C是D的一个连续子串.求D的最大可能长度. 很简单的一个DP ...

  7. collection 多态 会自动转型为子类 继承多态需要显示转型

  8. 【入门向】使用 MetaHook Plus 绘制 HUD

    MetaHook Plus 是一个GoldSrc引擎(就是的Half-Life.CS1.6的引擎)的客户端插件平台,它可以加载我们自己开发的DLL插件. 首先你需要安装一个 Visual Studio ...

  9. 【明哥报错簿】之【解决eclipse项目小红叉】

    解决方案: 0.如果是jdk版本不一致,直接右击项目名称,选择maven里面的update project.原因一般是maven的pom.xml里面设置的编译插件org.apache.maven.pl ...

  10. [三]SpringBoot 之 热部署

    如下配置 <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring ...