Codeforces Round 1092 (Unrated, Div. 2, Based on THUPC 2026 — Finals)
B
THU Packing Puzzle
Codeforces
1300
原题
← AC →
翻译中…

There are three types of 2D blocks: T-shaped, H-shaped, and U-shaped. Their exact shapes are shown in the figure below:

翻译中…

image

翻译中…

You are given three non-negative integers $c_T$, $c_H$, and $c_U$, representing the numbers of T-shaped, H-shaped, and U-shaped blocks, respectively. Your task is to pack all $(c_T + c_H + c_U)$ blocks into an $n \times 3$ grid, following these rules:

翻译中…
  • Every block must be placed entirely inside the grid;
  • No two blocks may overlap (i.e., no unit cell can be covered by more than one block);
  • Blocks can be rotated by any multiple of $90^{\circ}$, but their edges must remain parallel to the grid borders.
翻译中…

You have to find the minimum possible value of $n$ for which such a packing exists.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The only line of each test case contains three integers $c_T$, $c_H$, and $c_U$ ($0\le c_T,c_H,c_U\le 10^9$, $c_T+c_H+c_U \gt 0$) — the numbers of T-shaped, H-shaped, and U-shaped blocks, respectively.

翻译中…

Output

翻译中…

For each test case, output a single integer — the minimum possible value of $n$.

翻译中…

Note

翻译中…

The optimal solutions for the first three test cases are listed below:

翻译中…

image

翻译中…

样例

Input #1
5
1 1 1
2 0 0
1 1 0
0 0 1000000000
1000000000 1000000000 1000000000
Output #1
7
5
5
3000000000
7000000000
InputCopy OutputCopy
题目信息
题号
2216B
时间限制
1 s
内存限制
256 MB
标签
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。