#K39152. Taco Subarray Rearrangement

    ID: 26357 Type: Default 1000ms 256MiB

Taco Subarray Rearrangement

Taco Subarray Rearrangement

You are given an array of integers. Determine whether it is possible to rearrange the array such that, for every contiguous subarray of length k, the difference between the maximum and minimum element does not exceed a given threshold t.

Formally, let \(A\) be a rearrangement of the given array of length \(n\). For every index \(i\) with \(1 \le i \le n-k+1\), the condition \[ A[i+k-1] - A[i] \le t \] must hold. Output True if such a rearrangement is possible, and False otherwise.

Note: In our solution, sorting the array is a sufficient strategy to check the condition.

inputFormat

The input is given via stdin and consists of three lines:

  1. The first line contains an integer \(n\) (\(n \ge k\)), the number of elements in the array.
  2. The second line contains \(n\) space-separated integers representing the elements of the array.
  3. The third line contains two space-separated integers \(k\) and \(t\), where \(k\) is the length of the subarray and \(t\) is the threshold.

outputFormat

Output a single line to stdout containing either True if it is possible to rearrange the array to meet the condition, or False otherwise.

## sample
6
1 3 6 10 15 21
3 5
False