No.3288 Sloppy Land Grading
Problem Statement
You are given integers $A$, $B$, $C$. You may perform the following operations any number of times, possibly $0$.
- Add $+1$ or $-1$ to $A$. This operation costs $x$.
- Add $+1$ or $-1$ to $B$. This operation costs $y$.
- Add $+1$ or $-1$ to $C$. This operation costs $z$.
Find the minimum cost required to make $A$, $B$, $C$ all equal to the same value.
You are given $T$ test cases; find the answer for each of them.
Constraints
- $1 \le T \le 10^5$
- $1 \le A,B,C,x,y,z \le 10^5$
- All input values are integers.
Input
The input is given from Standard Input in the following format.
$T$ $case_1$ $case_2$ $\vdots$ $case_T$
Each test case $case_i$ is given in the following format.
$A\ B\ C\ x\ y\ z$
Output
Print $T$ lines.
On the $i$-th line, print the minimum cost required to make $A$, $B$, $C$ all equal to the same value for the $i$-th test case. Print a newline at the end.
Sample
Sample 1
Input
3 7 5 3 1 2 3 2 2 2 5 5 5 1 1 100000 100000 100000 100000
Output
8 0 9999900000
For the $1$st test case, consider making all of $A$, $B$, $C$ equal to $4$. The cost is $3$ to change $A$ from $7$ to $4$, $2$ to change $B$ from $5$ to $4$, and $3$ to change $C$ from $3$ to $4$, for a total of $8$. It is impossible to make $A$, $B$, $C$ equal at a smaller cost, so the answer is $8$.
For the $2$nd test case, $A$, $B$, $C$ already have the same value, so no operations are needed.
For the $3$rd test case, note that the answer may not fit in a signed 32-bit integer type.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
kona0001
drken1215