No.967 Subtract to Make a Kadomatsu Sequence (Part 2)
タグ : / 解いたユーザー数 123
作問者 :
nmnmnmnmnmnmnm
/ テスター :
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.
You are given 3 positive integers $A$, $B$, $C$ 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 $X$, subtract 1 from the positive integer $A$.
・At cost $Y$, subtract 1 from the positive integer $B$.
・At cost $Z$, subtract 1 from the positive integer $C$.
※Note that in this problem, one test case contains multiple queries.
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$ for 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 3 3 2 3 2 1
Output
4
Performing the operation of subtracting 1 from the left number $A$ twice gives "1 3 2", which makes a Kadomatsu sequence at cost 6.
Performing the operation of subtracting 1 from the middle number $B$ twice gives "3 1 2", which makes a Kadomatsu sequence at cost 4.
In this case, the minimum cost is 4.
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 5
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。