Congratulations to all the wizards and witches who participated in Codewarts!
Here is the official editorial for all the problems.
Round 1
Since $$$N$$$ is always even, try visualizing the array as $$$N/2$$$ independent, non-overlapping pairs: $$$(A_1,A_2), (A_3,A_4), \dots$$$
If every pair must sum to a multiple of $$$P$$$, what must the total sum $$$M$$$ be a multiple of? Given that numbers must be positive, what is the absolute minimum possible total sum?
To build the array, try repeating a simple pair like $$$(1,P-1)$$$ for most of the array, and put all the remaining required sum into the very last element.
When to print NO:
Because $$$N$$$ is even, we can split the array into exactly $$$N/2$$$ disjoint pairs. The problem requires every adjacent pair to sum to a multiple of $$$P$$$. Therefore, the sum of the entire array, $$$M$$$, must also be a multiple of $$$P$$$ ($$$M \bmod P = 0$$$).
Additionally, since the array requires strictly positive integers ($$$A_i \ge 1$$$), the smallest valid sum for any pair is $$$P$$$. With $$$N/2$$$ pairs, the absolute minimum total sum is $$$(N/2) \times P$$$.
If $$$M \lt (N/2) \times P$$$, it is impossible.
Therefore, if either of these conditions fails, print NO.
When to print YES:
If both conditions are met, print YES and construct the array greedily:
- Prefix: Fill the first $$$N-2$$$ positions by alternating $$$1$$$ and $$$P-1$$$: $$$1, P-1, 1, P-1, \dots$$$
Every adjacent pair here sums to exactly $$$P$$$.
- Second to last element: Set $$$A_{N-1} = 1$$$.
Since the prefix always ends in $$$P-1$$$, their sum is $$$P-1+1=P$$$, which is valid.
- Final element: Set $$$A_N$$$ to whatever value is needed to make the total array sum exactly $$$M$$$.
Since we already verified that $$$M \ge (N/2)\times P$$$, $$$A_N$$$ will always be a valid positive integer.
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
void solve()
{
int n, m, p;
cin >> n >> m >> p;
if ((m % p != 0) || ((m / p) < (n / 2)))
{
cout << "NO" << endl;
}
else
{
cout << "YES" << endl;
for (int i = 0; i < n - 2; i += 2)
{
cout << 1 << " " << p - 1 << " ";
m -= p;
}
cout << 1 << " " << m - 1 << endl;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}




