Codeforces
CF Step
Youtube Linkedin Discord Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Hints: THU Packing Puzzle

Each piece has a fixed area, but the height of an $n \times 3$ strip needed depends on how pieces share rows. First express the problem as a small set of macro patterns (how many rows one $T$, one $H$, or one $U$ needs when packed alone or combined).
Answer to Hint 1: In the model solution, the most important interaction is between $T$ and $U$: pairing them yields a very efficient block whose row cost is $4$ per such pair (see the min(t, u) * 4 term in model_sol.cpp).
Answer to Hint 2: After consuming $\min(t,u)$ pairs of that kind, leftover $T$’s can sometimes be combined with $H$’s in blocks of cost $7$ per two $T$’s with one $H$ (the 7 * min(h, t/2) part). If an odd $T$ remains with some $H$, one more $H$ can pay $5$ rows for a single leftover $T$.
Answer to Hint 3: Any $T$’s still unmatched after dealing with $H$ cost about $2$ rows per $T$ plus one extra row for the last stub (2 * t + 1 in the code). All remaining $H$’s and $U$’s are packed at $3$ rows each (3 * (u + h)).
Answer to Hint 4: Implement the cases exactly in the order used by model_sol.cpp: pair $T$ with $U$, then try $T$ with $H$, then clean up leftover $T$, then add the per-piece cost for remaining $H$ and $U$.