P6188 [NOI Online #1 Junior] Stationery Order
Description
Xiaoming’s class has a total class fund of $n$ yuan. The students plan to use the fund to collectively buy $3$ kinds of items:
1. Compass, $7$ yuan each.
2. Pen, $4$ yuan each.
3. Notebook, $3$ yuan each.
Xiaoming is responsible for ordering the stationery. Let the ordered quantities of compasses, pens, and notebooks be $a, b, c$ respectively. His ordering rules, in order, are:
1. The $n$ yuan must be spent exactly, i.e. $7a + 4b + 3c = n$.
2. Subject to the above condition, the number of complete sets should be as large as possible, i.e. $\min(a, b, c)$ should be as large as possible.
3. Subject to the above conditions, the total number of items should be as large as possible, i.e. $a + b + c$ should be as large as possible.
Please help Xiaoming find the optimal plan that satisfies the conditions. It can be proven that if a plan exists, then the optimal plan is unique.
Input Format
The input contains only one line with one integer, representing the class fund amount $n$.
Output Format
If there is no solution, output $-1$.
Otherwise, output one line with three integers $a, b, c$ separated by spaces, representing the numbers of compasses, pens, and notebooks.
Explanation/Hint
#### Explanation of Sample Input/Output 3
$a = 2, b = 4, c = 1$ is also a plan that satisfies conditions $1$ and $2$, but for condition $3$, this plan buys only $7$ items in total, which is worse than the plan $a = 1, b = 2, c = 6$.
#### Constraints
- For test points $1 \sim 6$, $n \leq 14$ is guaranteed.
- For test points $7 \sim 12$, $n$ is guaranteed to be a multiple of $14$.
- For test points $13 \sim 18$, $n \leq 100$ is guaranteed.
- For all test points, $0 \leq n \leq 10^5$ is guaranteed.
Translated by ChatGPT 5