AtCoder Beginner Contest 403(Promotion of AtCoder Career Design DAY)
D
Forbidden Difference
AtCoder
⌀ 1052
原题
←G →
翻译中…

Problem Statement

翻译中…

You are given a length-$N$ integer sequence $A=(A_1,A_2,\dots,A_N)$ and a non-negative integer $D$. We wish to delete as few elements as possible from $A$ to obtain a sequence $B$ that satisfies the following condition:

翻译中…
  • $|B_i - B_j|\neq D$ for all $i,j \; (1 \leq i < j \leq |B|)$.
翻译中…

Find the minimum number of deletions required.

翻译中…

Constraints

翻译中…
  • $1 \le N \le 2\times 10^5$
  • $0 \le D \le 10^6$
  • $0 \le A_i \le 10^6$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N D
A_1 A_2 \dots A_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
5 2
3 1 4 1 5
Output #1
1
Deleting $A_1=3$ yields $B=(1,4,1,5)$, which satisfies $|B_i - B_j|\neq 2$ for all $i
Input #2
4 3
1 6 1 8
Output #2
0
The sequence $A$ may already satisfy the condition.
Input #3
10 3
1 6 2 10 2 3 2 10 6 4
Output #3
2
题目信息
题号
abc403_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。