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. MySQL 基于lvm2的备份实战演练 (快照备份)

    前言: lvm2实现热备的原理是基于lvm2的快照功能,lvm2可以实现数据集不大的情况下的热备. 实战过程如下:这里的演示是在一台Mariadb服务器上进行创建快照,将快照中的文件scp到备份服务器 ...

  2. Centos7更改默认启动桌面(或命令行)模式

    centos7以后是这样的,7以前就是别的版本了 1.systemctl get-default命令获取当前模式 2.systemctl set-default graphical.target 修改 ...

  3. CentOS yum 安装LAMP PHP5.4版本

    CentOS yum 安装LAMP PHP5.4版本 [日期:2015-06-04] 来源:Linux社区  作者:rogerzhanglijie [字体:大 中 小]     Linux系统版本:C ...

  4. Q3 大型科技公司季报

    1. alphabet Alphabet(谷歌母公司)今天发布了截至9月30日的2018财年第三季度财报.报告显示,Alphabet第三季度总营收为337.40亿美元,比上年同期的277.72亿美元增 ...

  5. docker+mesos+marathon

    前言 (Core) [root@docker-slave ~]# uname -r 3.10.0-229.4.2.el7.x86_64 [root@docker-slave ~]# uname -m ...

  6. mysql 8 server windows 安装经验分享

    windows下安装一般分为文件/msi安装文件 本章我们说的是文件行的mysql server 安装 下载地址:https://dev.mysql.com/downloads/mysql/ 下载完后 ...

  7. vue中axios复用封装

    ajax2: function() { let that = this; return that .$http({ method: "get", url: "/Home/ ...

  8. [洛谷P4626]一道水题 II

    题目大意:求$lcm(1,2,3,\cdots,n)\pmod{100000007}$,$n\leqslant10^8$ 题解:先线性筛出质数,然后求每个质数最多出现的次数,可以用$\log_in$来 ...

  9. CF398B Painting The Wall 概率期望

    题意:有一个 $n * n$ 的网格,其中 $m$ 个格子上涂了色.每次随机选择一个格子涂色,允许重复涂,求让网格每一行每一列都至少有一个格子涂了色的操作次数期望.题解:,,这种一般都要倒推才行.设$ ...

  10. 【UOJ#188】Sanrd(min_25筛)

    [UOJ#188]Sanrd(min_25筛) 题面 UOJ 题解 今天菊开讲的题目.(千古神犇陈菊开,扑通扑通跪下来) 题目要求的就是所有数的次大质因子的和. 这个部分和\(min\_25\)筛中枚 ...