A11811 | Micro-World
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $a_i$ . Also you know intergalactic positive integer constant $K$ .
The $i$ -th bacteria can swallow the $j$ -th bacteria if and only if $a_i > a_j$ and $a_i \le a_j + 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 $a_i > a_j$ and $a_i \le a_j + 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, \underline{101}, 55, 54]$ $\to$ $[101, \underline{53}, 42, 102, 55, 54]$ $\to$ $[\underline{101}, 42, 102, 55, 54]$ $\to$ $[42, 102, 55, \underline{54}]$ $\to$ $[42, 102, 55]$ . In total there are $3$ 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.
You know that you have $n$ bacteria in the Petri dish and size of the $i$ -th bacteria is $a_i$ . Also you know intergalactic positive integer constant $K$ .
The $i$ -th bacteria can swallow the $j$ -th bacteria if and only if $a_i > a_j$ and $a_i \le a_j + 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 $a_i > a_j$ and $a_i \le a_j + 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, \underline{101}, 55, 54]$ $\to$ $[101, \underline{53}, 42, 102, 55, 54]$ $\to$ $[\underline{101}, 42, 102, 55, 54]$ $\to$ $[42, 102, 55, \underline{54}]$ $\to$ $[42, 102, 55]$ . In total there are $3$ 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.
输入格式
The first line contains two space separated positive integers $n$ and $K$ ( $1 \le n \le 2 \cdot 10^5$ , $1 \le K \le 10^6$ ) — number of bacteria and intergalactic constant $K$ .
The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^6$ ) — sizes of bacteria you have.
The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^6$ ) — sizes of bacteria you have.
输出格式
Print the only integer — minimal possible number of bacteria can remain.
输入输出样例
输入 #1
7 1 101 53 42 102 101 55 54
输出 #1
3
输入 #2
6 5 20 15 10 15 20 25
输出 #2
1
输入 #3
7 1000000 1 1 1 1 1 1 1
输出 #3
7
The first example is clarified in the problem statement.
In the second example an optimal possible sequence of swallows is: $[20, 15, 10, 15, \underline{20}, 25]$ $\to$ $[20, 15, 10, \underline{15}, 25]$ $\to$ $[20, 15, \underline{10}, 25]$ $\to$ $[20, \underline{15}, 25]$ $\to$ $[\underline{20}, 25]$ $\to$ $[25]$ .
In the third example no bacteria can swallow any other bacteria.
In the second example an optimal possible sequence of swallows is: $[20, 15, 10, 15, \underline{20}, 25]$ $\to$ $[20, 15, 10, \underline{15}, 25]$ $\to$ $[20, 15, \underline{10}, 25]$ $\to$ $[20, \underline{15}, 25]$ $\to$ $[\underline{20}, 25]$ $\to$ $[25]$ .
In the third example no bacteria can swallow any other bacteria.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted