#C905. Taco Special Orders
Taco Special Orders
Taco Special Orders
You are working in a popular taco dessert shop that offers special orders with a twist. The shop has a total of n desserts (although n is not directly used in the ordering process). A customer has a list of m favorite desserts. The chef prepares special orders that must consist of exactly k desserts.
However, due to quality and presentation requirements, there is a strict rule: each special order can contain at most one of the customer’s favourite desserts, with one small exception. In other words, it is only possible to cover all m favourite desserts if the distribution of these desserts into orders obeys the following feasibility condition:
Let \(r = m \mod k\). The arrangement is possible if and only if \(r \in \{0,1\}\), i.e. if \(m \mod k \le 1\). This condition can also be written in latex as:
[ m \leq \left\lfloor \frac{m}{k} \right\rfloor \times k + \mathbb{1}_{{m \mod k \neq 0}}, ]
Your task is to determine whether it is possible to form these special orders to cover all the customer's preferred desserts under the given constraints.
inputFormat
The input begins with a single integer T (1 ≤ T ≤ 10), the number of test cases. Each test case is described as follows:
- First line: Three space-separated integers n, m, and k, where n is the total number of desserts (unused in logic), m is the number of favorite desserts, and k is the fixed number of desserts in each special order.
- Second line: m space-separated integers representing the IDs of the customer's favorite desserts.
All input is read from standard input (stdin).
outputFormat
For each test case, output a single line containing either YES
if it is possible to arrange the special orders to satisfy the customer’s preferences, or NO
otherwise. All output should be written to standard output (stdout).
3
5 3 2
1 3 5
6 4 2
2 4 5 6
8 5 3
1 2 3 7 8
YES
YES
NO
</p>