Gadol
You are planning to renovate a broken wall made with bricks. The wall has N columns for you to lay bricks.
Some of the columns already have a number of old bricks remaining. Weirdly, you have a strange sense of art and decided to fill-in the N columns in a way that it follows the following rules:
- At most K new bricks can be laid in each column, one on top of the other contiguously
- Consecutive columns should have at least a single newly laid brick in each column, sharing a common side.
- New bricks laid out in the first and last columns should touch the ground/ an old brick.
- You may leave a space of maximum height K-1 in each column between the new bricks and the old bricks (or the ground in case no old bricks are there), for ventilation
Given N, K, and an array A of length N containing the number of old bricks present in each column, print whether it is possible to lay out the new bricks following the specified rules.
Input Format
The first line contains a single integer T the number of test cases. The first line of each test case contains two integers N, and K separated by a space. Second line of each test case contains a list of N integers, corresponding to the array A, separated by spaces.
Output Format
Print “YES” if it’s possible to lay out the bricks following the rules. “NO” if it is impossible.
Constraints
- 1 \(\leq\) T \(\leq\) 104
- 2 \(\leq\) N \(\leq\) 2x105
- 2 \(\leq\) K \(\leq\) 108
- 0 \(\leq\) Ai \(\leq\) 108
Sample Input 0
3
6 3
0 0 2 5 1 1
2 3
0 2
3 2
3 0 2
Sample Output 0
YES
YES
NO
Open on HackerRank ↗ · Markdown source · Back to the archive