問題一覧 > 通常問題

No.3288 Sloppy Land Grading

レベル : / AI推定難易度 : 500 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 108
作問者 : kona0001 / テスター : tobisatis RyosukeFukatani koba-e964 ir5 drken1215
お気に入りにしたユーザー ProblemId : 12633 / 自分の提出
問題文最終更新日: 2025-09-24 00:54:43
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 485 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。