#K59982. Maximal Spaced Subsequence

    ID: 30985 Type: Default 1000ms 256MiB

Maximal Spaced Subsequence

Maximal Spaced Subsequence

You are given a sequence of n integers and an integer d. Your task is to find the maximum possible length of a subsequence such that the absolute difference between any two consecutive elements in the subsequence is at least d.

Formally, given a sequence \(a_1, a_2, \dots, a_n\), determine the largest integer \(k\) for which there exists indices \(i_1 < i_2 < \dots < i_k\) such that for every \(1 \leq j < k\), the following holds:

\(|a_{i_{j+1}} - a_{i_j}| \geq d\)

Note: In order to simplify the problem, you may consider sorting the sequence as part of your approach.

inputFormat

The input is read from standard input. The first line contains two integers n and d, where n is the number of integers in the sequence and d is the minimum required absolute difference between consecutive elements of the subsequence.

The second line contains n space-separated integers representing the sequence.

outputFormat

Output a single integer representing the maximal possible length of the subsequence that satisfies the condition.

## sample
5 3
1 5 3 9 7
3