Micro-World
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
input

Copy
7 1
101 53 42 102 101 55 54
output

Copy
3
input

Copy
6 5
20 15 10 15 20 25
output

Copy
1
input

Copy
7 1000000
1 1 1 1 1 1 1
output

Copy
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,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.

题意: 有n个细菌,每个细菌的尺寸为ai,现在有以常数k,如果细菌i的尺寸ai大于细菌j的尺寸aj,并且ai<=aj+k,那么细菌i就可以吃掉细菌j,问最后可以剩于多少个细菌。

先将n个细菌去重排序并且用vis数组记录下每个细菌的个数,然后直接暴力枚举满足a[i]>=a[i-1]&&[i]<=a[i-1]+k的情况,减去满足情况a[i-1]的个数

#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = 1e6 + ;
const int mod = 1e9 + ;
typedef long long ll;
ll a[maxn], vis[maxn*], flg[maxn];
int main(){
std::ios::sync_with_stdio(false);
ll n, k;
while( cin >> n >> k ) {
ll num;
memset( vis, , sizeof(vis) );
for( ll i = ; i < n; i ++ ) {
cin >> a[i];
vis[a[i]] ++;
}
sort( a, a + n );
ll sum = n, len = unique( a, a + n ) - a;
for( ll i = ; i < len; i ++ ) {
if( a[i] > a[i-] && a[i] <= a[i-] + k ) {
sum -= vis[a[i-]];
}
}
cout << sum << endl;
}
return ;
}

CF990B Micro-World 贪心 第十六的更多相关文章

  1. S3C2416裸机开发系列十六_sd卡驱动实现

    S3C2416裸机开发系列十六 sd卡驱动实现 象棋小子    1048272975 SD卡(Secure Digital Memory Card)具有体积小.容量大.传输数据快.可插拔.安全性好等长 ...

  2. 经典算法题每日演练——第十六题 Kruskal算法

    原文:经典算法题每日演练--第十六题 Kruskal算法 这篇我们看看第二种生成树的Kruskal算法,这个算法的魅力在于我们可以打一下算法和数据结构的组合拳,很有意思的. 一:思想 若存在M={0, ...

  3. Alink漫谈(十六) :Word2Vec源码分析 之 建立霍夫曼树

    Alink漫谈(十六) :Word2Vec源码分析 之 建立霍夫曼树 目录 Alink漫谈(十六) :Word2Vec源码分析 之 建立霍夫曼树 0x00 摘要 0x01 背景概念 1.1 词向量基础 ...

  4. 我的MYSQL学习心得(十六) 优化

    我的MYSQL学习心得(十六) 优化 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据 ...

  5. Bootstrap <基础二十六>进度条

    Bootstrap 进度条.在本教程中,你将看到如何使用 Bootstrap 创建加载.重定向或动作状态的进度条. Bootstrap 进度条使用 CSS3 过渡和动画来获得该效果.Internet ...

  6. Bootstrap<基础十六> 导航元素

    Bootstrap 提供的用于定义导航元素的一些选项.它们使用相同的标记和基类 .nav.Bootstrap 也提供了一个用于共享标记和状态的帮助器类.改变修饰的 class,可以在不同的样式间进行切 ...

  7. 解剖SQLSERVER 第十六篇 OrcaMDF RawDatabase --MDF文件的瑞士军刀(译)

    解剖SQLSERVER 第十六篇 OrcaMDF RawDatabase --MDF文件的瑞士军刀(译) http://improve.dk/orcamdf-rawdatabase-a-swiss-a ...

  8. Senparc.Weixin.MP SDK 微信公众平台开发教程(十六):AccessToken自动管理机制

    在<Senparc.Weixin.MP SDK 微信公众平台开发教程(八):通用接口说明>中,我介绍了获取AccessToken(通用接口)的方法. 在实际的开发过程中,所有的高级接口都需 ...

  9. JAVA-集合作业-已知有十六支男子足球队参加2008 北京奥运会。写一个程序,把这16 支球队随机分为4 个组。采用List集合和随机数

    第二题 已知有十六支男子足球队参加2008 北京奥运会.写一个程序,把这16 支球队随机分为4 个组.采用List集合和随机数 2008 北京奥运会男足参赛国家: 科特迪瓦,阿根廷,澳大利亚,塞尔维亚 ...

随机推荐

  1. 基于python的Elasticsearch索引的建立和数据的上传

    这是我的第一篇博客,还请大家多多指点 Thanks ♪(・ω・)ノ         今天我想讲一讲关于Elasticsearch的索引建立,当然提前是你已经安装部署好Elasticsearch. ok ...

  2. ipad pro 为什么不行

    TalkingData公布的数据显示,iPad Pro在中国发行首月的销量仅为49 300台,而此前iPad Air 2发行首月后销量曾高达55.7万台.那么到底是什么原因,让这个被寄予厚望的iPad ...

  3. openjdk:8u22-jre-alpine在java开发中的NullPointerException错误解决方案

    问题描述 ** 在SpringBoot项目中使用了Ureport报表组件, 打包发布部署到docker中启动报错 ** java.lang.NullPointerException at sun.aw ...

  4. Mysql索引进阶入门

    1. 索引操作 MySQL 索引 菜鸟 2. 索引类型 PRIMARY 唯一且不能为空:一张表只能有一个主键索引 INDEX 普通索引 UNIQUE 唯一性索引 FULLTEXT 全文索引:用于搜索很 ...

  5. 在canvas中使用其他HTML元素

    做一个功能如下图,随机生成100个大小.颜色随机的小球.点击开始运动的时候,小球开始运动,然后点击停止运动的时候,小球停止运动. 点击旁边的白色或者黑色,则背景颜色变为相应的颜色. HTML部分: & ...

  6. vue组件传值之$attrs、$listeners

    当有父组件A,子组件B,孙子组件C的时候 A-B B-C 的传值想必大家应该都非常熟悉了,通过props和$emit和$on来进行传值 那么A-C之间的传值要怎么做呢? 1.event.bus总线传值 ...

  7. Spring boot实战项目整合阿里云RocketMQ (非开源版)消息队列实现发送普通消息,延时消息 --附代码

    一.为什么选择RocketMQ消息队列? 首先RocketMQ是阿里巴巴自研出来的,也已开源.其性能和稳定性从双11就能看出来,借用阿里的一句官方介绍:历年双 11 购物狂欢节零点千万级 TPS.万亿 ...

  8. 深度搜索(dfs)+典型例题(八皇后)

    深度优先搜索简称深搜,从起点出发,走过的点要做标记,发现有没走过的点,就随意挑一个往前走,走不了就回退,此种路径搜索策略就称为“深度优先搜索”,简称“深搜”. 如上面的图所示:加入我们要找一个从V0到 ...

  9. Could not determine type for java util List

    问题场景:在实体类中需要使用List集合存储字段,启动时找不到List类型 问题解决:在字段上添加@ElementColletion(targetClass=String.class)表示是一个集合映 ...

  10. Sublime Text 3 使用手册

    Ctrl+Shift+P:打开命令面板 Ctrl+P:搜索项目中的文件 Ctrl+G:跳转到第几行 Ctrl+W:关闭当前打开文件 Ctrl+Shift+W:关闭所有打开文件 Ctrl+Shift+V ...