CF990B.Micro-World

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 aia_i. Also you know intergalactic positive integer constant KK.

The ii-th bacteria can swallow the jj-th bacteria if and only if ai>aja_i \gt a_j and ai≤aj+Ka_i \le a_j + 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>aja_i \gt a_j and ai≤aj+Ka_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]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, \underline{101}, 55, 54] →\to [101,53‾,42,102,55,54][101, \underline{53}, 42, 102, 55, 54] →\to [101‾,42,102,55,54][\underline{101}, 42, 102, 55, 54] →\to [42,102,55,54‾][42, 102, 55, \underline{54}] →\to [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.

你有一个装有细菌的培养皿,正准备潜入这个严酷的微观世界。但不幸的是,你身边没有显微镜,因此无法直接观察它们。

已知培养皿中有 nn 个细菌,其中第 ii 个细菌的大小为 aia_i。同时你还知道一个星际正整数常量 KK。

当且仅当 ai>aja_i \gt a_j 且 ai≤aj+Ka_i \le a_j + K 时,第 ii 个细菌可以吞食第 jj 个细菌。此时第 jj 个细菌消失,而第 ii 个细菌的大小保持不变。细菌可以进行多次吞食操作:在每次吞食操作中,任意细菌 ii 可以吞食任意细菌 jj,只要满足 ai>aja_i \gt a_j 且 ai≤aj+Ka_i \le a_j + K。吞食操作依次进行。

例如,细菌大小序列为 a=[101,53,42,102,101,55,54]a=[101, 53, 42, 102, 101, 55, 54],且 K=1K=1。一种可能的吞食序列如下:
[101,53,42,102,101‾,55,54][101, 53, 42, 102, \underline{101}, 55, 54] →\to [101,53‾,42,102,55,54][101, \underline{53}, 42, 102, 55, 54] →\to [101‾,42,102,55,54][\underline{101}, 42, 102, 55, 54] →\to [42,102,55,54‾][42, 102, 55, \underline{54}] →\to [42,102,55][42, 102, 55]。最终培养皿中剩余 33 个细菌。

由于你没有显微镜,你只能猜测:当你最终找到显微镜时,培养皿中可能剩余的细菌数量的最小值是多少?

输入格式

The first line contains two space separated positive integers nn and KK (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 1≤K≤1061 \le K \le 10^6) — number of bacteria and intergalactic constant KK.

The second line contains nn space separated integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1061 \le a_i \le 10^6) — sizes of bacteria you have.

第一行包含两个用空格分隔的正整数 nn 和 KK(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,1≤K≤1061 \le K \le 10^6)——分别为细菌的数量和星际常数 KK。

第二行包含 nn 个用空格分隔的整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1061 \le a_i \le 10^6)——表示你所拥有的细菌的尺寸。

输出格式

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,20‾,25][20, 15, 10, 15, \underline{20}, 25] →\to [20,15,10,15‾,25][20, 15, 10, \underline{15}, 25] →\to [20,15,10‾,25][20, 15, \underline{10}, 25] →\to [20,15‾,25][20, \underline{15}, 25] →\to [20‾,25][\underline{20}, 25] →\to [25][25].

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

第一个示例已在题目描述中阐明。

在第二个示例中,一种最优的吞食序列如下:[20,15,10,15,20‾,25][20, 15, 10, 15, \underline{20}, 25] →\to [20,15,10,15‾,25][20, 15, 10, \underline{15}, 25] →\to [20,15,10‾,25][20, 15, \underline{10}, 25] →\to [20,15‾,25][20, \underline{15}, 25] →\to [20‾,25][\underline{20}, 25] →\to [25][25]。

在第三个示例中,没有任何细菌能够吞食其他细菌。

输入解题思路,AI测评打分。不知道怎么写?

首页