No.2110 012 Matching
Problem Statement
There are $A$ balls with $0$ written on them, $B$ balls with $1$ written on them, and $C$ balls with $2$ written on them.
You repeat the following operation until the total number of remaining balls is $1$ or less.
- Choose $2$ of the remaining balls and eat them at the same time. If the numbers written on the eaten balls were $x,y$ respectively, you gain a satisfaction of $(x+y)\bmod 3$.
Here, $a \bmod b$ denotes the remainder when $a$ is divided by $b$.
Find the maximum possible total satisfaction you can gain when you choose the sequence of operations optimally.
Answer $T$ test cases for each $1$ input file.
Input
$T$ $case_1$ $case_2$ : $case_T$Each test case is given in the following format.
$A\ B\ C$
- $1\le T \le 10^5$
- $0\le A,B,C\le 10^{18}$
- All input values are integers
Output
Output the answers. On the $i$-th line, output the answer to the $i$-th test case.
Sample
Sample 1
Input
3 1 1 2 1 1 1 1000000000000000000 1000000000000000000 1000000000000000000
Output
2 2 3000000000000000000
In the $1$-st test case, the total satisfaction can be maximized, for example, by performing the operations as follows.
- Choose a ball with $0$ written on it and a ball with $1$ written on it, and eat them. You gain a satisfaction of $(0+1)\bmod 3=1$.
- Choose a ball with $2$ written on it and a ball with $2$ written on it, and eat them. You gain a satisfaction of $(2+2)\bmod 3=1$.
The total satisfaction cannot be made $3$ or more, so output $2$.
In the $2$-nd test case, you can make the total satisfaction $2$ by eating the ball with $0$ written on it and the ball with $2$ written on it.
Note that $1$ ball with $1$ written on it remains, but balls can only be eaten $2$ at a time.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
bayashiko