问题 G: Cyperation

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:4 通过:2

题目描述

链接:https://ac.nowcoder.com/acm/contest/57361/G
来源:牛客网
Given a circular array aaa of length nnn and a positive integer kkk, you can perform the following operation any number of times (including zero):
  • Select two indices iii and jjj (1≤i<j≤n1 \leq i < j \leq n1i<jn) such that min⁡(j−i,n+i−j)=k\min(j-i, n+i-j) = kmin(ji,n+ij)=k, which means the minimum distance between iii and jjj on the circular array is kkk, and subtract 111 from both aia_iai and aja_jaj.
Determine if it is possible to transform the entire array into 000. If possible, outputYES; otherwise, outputNO. 
You are given TTT test cases. Find the answer for each of them.

输入格式

The first line contains a positive integer TTT (1≤T≤1061 \leq T \leq 10^61T106) , denoting the number of test cases. The first line of each test case contains two positive integers nnn and kkk (2≤n≤1062 \leq n \leq 10^62n106, 1≤k≤n1 \leq k \leq n1kn), indicating the length of the array aaa and the minimum distance of iii and jjj for each index selection. The second line consists of nnn non-negative integers aia_iai (0≤ai≤1090 \leq a_i \leq 10^90ai109).

It is guaranteed that 2≤∑n≤1062 \leq \sum n \leq 10^62n106.

输出格式

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

输入样例 复制

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)(1,3),(1,3),(1,4),(3,5),(3,5),(3,5)(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 000.