#K86082. Reordering Array Based on Adjacent Differences

    ID: 36785 Type: Default 1000ms 256MiB

Reordering Array Based on Adjacent Differences

Reordering Array Based on Adjacent Differences

You are given an array of integers of length \(N\) and an integer \(k\). Your task is to determine whether it is possible to reorder the array such that for every two consecutive elements \(a_i\) and \(a_{i+1}\), the following condition holds:

\(|a_i - a_{i+1}| \le k\)

It can be proven that sorting the array produces the minimum possible adjacent differences. Thus, if the sorted array satisfies the above inequality for all adjacent pairs, then a valid reordering exists. Otherwise, it is not possible.

inputFormat

The input is given via stdin and consists of multiple test cases. The first line contains an integer \(T\), denoting the number of test cases. Each test case is described as follows:

  • An integer \(N\) representing the number of elements in the array.
  • A line with \(N\) space-separated integers representing the array.
  • An integer \(k\) representing the maximum allowed absolute difference between any two consecutive elements after reordering.

outputFormat

For each test case, output a single line to stdout containing either "Reordering is possible." if a valid reordering exists, or "Reordering is not possible." otherwise.

## sample
1
4
3 1 4 5
2
Reordering is possible.

</p>