1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118 | // https://codeforces.com/problemset/problem/1352/B
pub struct Input<I: std::io::BufRead> {
std: I,
buffer: Vec<String>,
}
impl<I: std::io::BufRead> Input<I> {
pub fn new(std: I) -> Self {
return Self {
std: std,
buffer: Vec::new(),
};
}
pub fn raw(&mut self) -> String {
let mut string = String::new();
self.std.read_line(&mut string).unwrap();
return string;
}
pub fn text(&mut self) -> String {
return self.raw().trim().to_string();
}
pub fn next(&mut self) -> String {
loop {
match self.buffer.pop() {
Some(token) => return token,
None => {
self.buffer = self
.raw()
.split_whitespace()
.rev()
.map(String::from)
.collect();
}
};
}
}
pub fn scalar<T>(&mut self) -> T
where
T: std::str::FromStr,
{
return self.next().parse().ok().unwrap();
}
pub fn vector<T>(&mut self, n: usize) -> Vec<T>
where
T: std::str::FromStr,
{
return (0..n).map(|_| self.scalar()).collect();
}
}
struct Problem {}
impl Problem {
fn new() -> Self {
return Problem {};
}
fn solve(&self, n: i32, k: i32) -> Option<Vec<i32>> {
let x = n - k + 1;
if x > 0 && x % 2 == 1 {
let mut ans = vec![1; k as usize];
ans[0] = x;
return Some(ans);
}
let y = n - 2 * k + 2;
if y > 0 && y % 2 == 0 {
let mut ans = vec![2; k as usize];
ans[0] = y;
return Some(ans);
}
return None;
}
fn via_io<I, O>(self, mut stdin: I, mut stdout: O)
where
I: std::io::BufRead,
O: std::io::Write,
{
let mut input = Input::new(&mut stdin);
for _ in 0..input.scalar::<u16>() {
let (n, k) = (input.scalar(), input.scalar());
match self.solve(n, k) {
Some(ak) => {
let strings: Vec<String> = ak.iter().map(|a| a.to_string()).collect();
writeln!(stdout, "YES").unwrap();
writeln!(stdout, "{}", strings.join(" ")).unwrap();
}
None => writeln!(stdout, "NO").unwrap(),
};
}
}
fn _test(input: &str) -> String {
let mut output = Vec::new();
let problem = Self::new();
problem.via_io(input.as_bytes(), &mut output);
return String::from_utf8(output).unwrap();
}
}
#[cfg(test)]
mod test {
#[test]
fn case_1() {
assert_eq!(crate::Problem::_test("8\n10 3\n100 4\n8 7\n97 2\n8 8\n3 10\n5 3\n1000000000 9\n"), "YES\n6 2 2\nYES\n97 1 1 1\nNO\nNO\nYES\n1 1 1 1 1 1 1 1\nNO\nYES\n3 1 1\nYES\n999999984 2 2 2 2 2 2 2 2\n");
}
}
fn main() {
let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
let output = std::io::BufWriter::new(stdout.lock());
Problem::new().via_io(stdin.lock(), output);
}
|