#C10702. Beautiful Array Reordering

    ID: 39937 Type: Default 1000ms 256MiB

Beautiful Array Reordering

Beautiful Array Reordering

You are given an array of integers \(A = [a_1, a_2, \dots, a_n]\) and an integer \(k\). An array is called beautiful if it can be rearranged such that for every pair of consecutive elements in the resulting array, \(a_{i+1} - a_i \le k\) for all \(1 \le i < n\). Your task is to determine whether it is possible to rearrange the given array into a beautiful array.

Input/Output Interface

The input is read from standard input and the output should be written to standard output.

inputFormat

The first line contains two space-separated integers \(n\) and \(k\), where \(n\) is the number of elements in the array and \(k\) is the maximum allowed difference between consecutive elements. The second line contains \(n\) space-separated integers representing the elements of the array.

outputFormat

Output a single line containing YES if it is possible to rearrange the array into a beautiful array; otherwise, output NO.

## sample
4 1
1 3 2 4
YES

</p>