No.968 Subtract to Make a Kadomatsu Sequence (Part 3)
タグ : / 解いたユーザー数 76
作問者 :
nmnmnmnmnmnmnm
/ テスター :
37zigen
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 left to right.
Perform the following 3 operations any number of times to make a Kadomatsu sequence at the minimum cost.
・At cost $X$, subtract 1 from the positive integers $A$ and $B$.
・At cost $Y$, subtract 1 from the positive integers $B$ and $C$.
・At cost $Z$, subtract 1 from the positive integers $A$ and $C$.
※Note that in this problem, multiple queries are given in a single test case.
Input
$T$ $A_1$ $B_1$ $C_1$ $X_1$ $Y_1$ $Z_1$ $A_2$ $B_2$ $C_2$ $X_2$ $Y_2$ $Z_2$ $ \vdots\ $ $A_T$ $B_T$ $C_T$ $X_T$ $Y_T$ $Z_T$
$T$ is the number of given sets of 6 positive integers $A$, $B$, $C$, $X$, $Y$, $Z$. $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$.
$X_i$, $Y_i$, $Z_i$ are the costs $X$, $Y$, $Z$ in the $i$-th case. $1 \le X_i,Y_i,Z_i \le 1000000000 = 10^9$.
Output
On the $i$-th line, output the answer for the $i$-th $A_i$, $B_i$, $C_i$, $X_i$, $Y_i$, $Z_i$.
If a Kadomatsu sequence cannot be made, output -1.
Sample
Sample 1
Input
1 2 4 2 2 1 1
Output
1
Performing once the operation of subtracting 1 from the left and middle numbers $A$ and $B$ gives "1 3 2", making a Kadomatsu sequence at cost 2.
Performing once the operation of subtracting 1 from the middle and right numbers $B$ and $C$ gives "2 3 1", making a Kadomatsu sequence at cost 1.
In this case, the minimum cost is 1.
Sample 2
Input
3 1 3 2 1 2 3 1 2 3 1 2 3 3 3 3 1 2 3
Output
0 -1 -1
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。