#P8344. Wooden Plank Container
Wooden Plank Container
Wooden Plank Container
You are given x golden wooden planks, y silver wooden planks, and an empty container with capacity z planks. The rules for insertion are as follows:
- You can insert a wooden plank (golden or silver) into the container if the container has available capacity.
- If you insert a golden wooden plank, after the insertion, all silver wooden planks currently in the container are discarded. However, before inserting a golden plank, you must ensure that the container has room for at least one more plank (i.e. it is not completely full).
- Silver wooden planks, once inserted, remain in the container unless later discarded by a golden insertion.
The objective is to determine whether there exists an order of insertions so that every wooden plank (both golden and silver) is inserted into the container at least once (even if it is later discarded).
Note: The container’s state changes over time. In particular, when a golden plank is inserted, the silver planks in the container are cleared while the golden ones remain. At the end, all planks must have been inserted at some moment although they need not remain in the container.
Analysis:
Let the number of golden planks be \(x\), silver planks be \(y\), and container capacity be \(z\). A necessary condition is that \(x \le z\) because after inserting all golden planks (which are never removed), the container will hold \(x\) planks.
The silver planks may be inserted in several blocks between golden insertions. Specifically, if you consider the following strategy:
- Before the first golden insertion, you may insert at most \(z-1\) silver planks (to guarantee the container is not full before inserting a golden plank).
- After the \(i\)th golden insertion (with \(1 \le i \le x-1\)), the container holds exactly \(i\) golden planks, so you can insert at most \(z-1-i\) silver planks before the next golden plank.
- After the last golden insertion, the container has \(x\) planks, so you can insert at most \(z-x\) silver planks.
Thus, the maximum number of silver planks that can be inserted is
[ y_{\max} = (z-1) + \sum_{i=1}^{x-1} (z-1-i) + (z-x) = z(x+1) - \frac{x^2+3x}{2}. ]
The answer is YES
if and only if both conditions hold:
- \(x \le z\)
- \(y \le z(x+1) - \frac{x^2+3x}{2}\)
Otherwise, the answer is NO
.
inputFormat
The first line contains an integer T (the number of test cases). Each of the following T lines contains three integers x, y, and z, separated by spaces.
\(1 \le T \le 10^4\), and all other numbers are non-negative integers with appropriate limits.
outputFormat
For each test case, output a single line containing YES
if there is a valid sequence of insertions, or NO
otherwise.
sample
1
1 0 1
YES
</p>