Cyperation
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Given a circular array a of length n and a positive integer k, you can perform the following operation any number of times (including zero):
  • Select two indices i and j (1 \leq i < j \leq n) such that \min(j-i, n+i-j) = k, which means the minimum distance between i and j on the circular array is k, and subtract 1 from both a_i and a_j.
Determine if it is possible to transform the entire array into 0. If possible, output YES; otherwise, output NO
You are given T test cases. Find the answer for each of them.

输入描述:

The first line contains a positive integer T (1 \leq T \leq 10^6) , denoting the number of test cases. The first line of each test case contains two positive integers n and k (2 \leq n \leq 10^6, 1 \leq k \leq n), indicating the length of the array a and the minimum distance of i and j for each index selection. The second line consists of n non-negative integers a_i (0 \leq a_i \leq 10^9).

It is guaranteed that 2 \leq \sum n \leq 10^6.

输出描述:

For each test case, output one string per line, either "YES" or "NO" (without quotes), indicating whether it is possible or not.
示例1

输入

复制
5
5 2
3 0 5 1 3
6 3
5 0 0 3 0 0
5 5
1 2 3 4 5
6 1
0 0 1 0 0 1
7 2
1 1 0 1 1 1 1

输出

复制
YES
NO
NO
NO
YES

说明

For the first test case, perform these operations: (1,3),(1,3),(1,4),(3,5),(3,5),(3,5).
For the third test case, you can't do any operation, so it's impossible to transform the entire array into 0.