| ICPC India Online Prelims (2025 - 2026) |
|---|
| Закончено |
You are given an array $$$a$$$ of length $$$n$$$ and a non-negative integer $$$d$$$.
Is it possible to rearrange $$$a$$$ in such a way that $$$|a_i - a_{n + 1 - i}| \le d$$$ for all $$$i$$$ ($$$1 \le i \le n$$$)?
The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases.
The first line of each test case contains integers $$$n$$$ and $$$d$$$ ($$$1 \le n \le 2000$$$, $$$0 \le d \le 10^9$$$) — the length of $$$a$$$ and the integer $$$d$$$.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \le 10^9$$$) — the elements of the array $$$a$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$.
For each test case, output "YES" if it is possible to rearrange $$$a$$$. Otherwise, output "NO". You can output "YES" and "NO" in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive response).
31 112 01 22 10001 2
YESNOYES
In the first test case, the given array is already valid.
In the second test case, it can be proven that there is no valid rearrangement of $$$a$$$.
In the third test case, the valid rearrangements are $$$[1, 2]$$$ and $$$[2, 1]$$$.
| Название |
|---|


