#C8386. Taco: Arrays Non-Decreasing Transformation

    ID: 52362 Type: Default 1000ms 256MiB

Taco: Arrays Non-Decreasing Transformation

Taco: Arrays Non-Decreasing Transformation

You are given an array of non-negative integers and an integer \(k\). For each element \(a_i\) in the array, you can change its value to any integer in the range \([\max(0, a_i - k),\; a_i + k]\). Your task is to determine whether it is possible to choose a value for each element such that the resulting array is non-decreasing, i.e., \(b_1 \le b_2 \le \dots \le b_n\).

If such a selection exists, output YES for that test case; otherwise, output NO.

inputFormat

The input is given via standard input and consists of multiple test cases. The first line contains an integer \(t\) \((1 \le t \le 10^4)\) which denotes the number of test cases. Each test case is described as follows:

  • The first line of a test case contains two integers \(n\) and \(k\) \((1 \le n \le 10^5,\; 0 \le k \le 10^9)\), where \(n\) is the number of elements in the array.
  • The second line contains \(n\) non-negative integers \(a_1, a_2, \dots, a_n\) \((0 \le a_i \le 10^9)\).

outputFormat

For each test case, print a single line containing YES if it is possible to transform the array into a non-decreasing array by choosing appropriate values from the allowed ranges; otherwise, print NO.

## sample
3
4 5
4 6 8 10
3 3
2 6 8
5 10
20 15 10 5 0
YES

YES YES

</p>