問題一覧 > 通常問題

No.966 Subtract to Make a Kadomatsu Sequence (Part 1)

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 162
作問者 : nmnmnmnmnmnmnm / テスター : uwi
お気に入りにしたユーザー ProblemId : 3607 / 自分の提出
問題文最終更新日: 2020-01-13 19:46:04
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 233 (順位表) の他の問題:

Problem Statement

A Kadomatsu sequence is defined as follows: when 3 integers are arranged as $A$, $B$, $C$ from left to right,
all the values are distinct and the second largest integer among $A$, $B$, $C$ is either $A$ or $C$.
In particular, in this problem, $A$, $B$, $C$ of a Kadomatsu sequence must be positive integers.

3 positive integers $A$, $B$, $C$ are given in this order from the left.
Perform the 3 operations below any number of times to make a Kadomatsu sequence at the minimum cost.

・At cost 1, subtract 1 from the positive integer $A$.
・At cost 1, subtract 1 from the positive integer $B$.
・At cost 1, subtract 1 from the positive integer $C$.

※Note that in this problem, multiple queries are given in one test case.

Input

$T$
$A_1$ $B_1$ $C_1$
$A_2$ $B_2$ $C_2$
$ \vdots\ $
$A_T$ $B_T$ $C_T$

$T$ is the number of given triples of positive integers $A$, $B$, $C$. $1 \le T \le 10000 = 10^4$.
$A_i$, $B_i$, $C_i$ are the $i$-th given positive integers $A$, $B$, $C$. $1 \le A_i,B_i,C_i \le 1000000000 = 10^9$.

Output

On the $i$-th line, output the answer for the $i$-th $A_i$, $B_i$, $C_i$.
If a Kadomatsu sequence cannot be made, output -1.

Sample

Sample 1
Input
1
4 3 2
Output
2

Performing the operation of subtracting 1 from the left number $A$ 3 times gives "1 3 2", which makes a Kadomatsu sequence at cost 3.
Performing the operation of subtracting 1 from the middle number $B$ 2 times gives "4 1 2", which makes a Kadomatsu sequence at cost 2.
In this case, the minimum cost is 2.

Sample 2
Input
3
1 3 2
1 2 3
3 3 3
Output
0
-1
3

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。