#![allow(unused_imports)] fn main() { input! { t: usize, } for _ in 0..t { input! { n: usize, k: usize, x: i64, h: [i64; n], } if h.iter().any(|&hh| (hh - h[0]) % x != 0) { println!("No"); continue; } let h: Vec<_> = h.iter().map(|hh| (hh - h[0]) / x).collect(); let mut s = vec![0; n + 1]; for i in 0..n { s[i + 1] = h.get(i + 1).unwrap_or(&0) - h[i]; } for i in 0..=n - k { if s[i] < 0 { s[i + k] += s[i]; s[i] = 0; } } for i in (k..=n).rev() { if s[i] > 0 { s[i - k] += s[i]; s[i] = 0; } } if s[0] == -s[n] && s[1..n].iter().all(|&s| s == 0) { println!("Yes"); } else { println!("No"); } } } /* imos? l..r += 1 => l += 1, r -= 1 k = 2 0 -1 0 1 => 0 -1 1 1 -1 k = 3 0 -3 -3 1 3 0 1 2 => 0 -3 0 4 2 -3 1 1 -2 k = 2 0 1 1 0 => 0 1 0 -1 0 k = 2 0 0 1 1 => 0 0 1 0 -1 k = 1 0 1 2 3 => 0 1 1 1 -3 a 0 .. 0 -a */ use proconio::{input, marker::*}; use std::{cmp::Reverse, collections::*}; #[macro_export] macro_rules! chmax { ($a:expr, $b:expr) => {{ let tmp = $b; if $a < tmp { $a = tmp; true } else { false } }}; } #[macro_export] macro_rules! chmin { ($a:expr, $b:expr) => {{ let tmp = $b; if $a > tmp { $a = tmp; true } else { false } }}; } #[macro_export] /// mvec![] macro_rules! mvec { ($val:expr; ()) => { $val }; ($val:expr; ($size:expr $(,$rest:expr)*)) => { vec![mvec![$val; ($($rest),*)]; $size] }; }