func main() var T: int :: cui@input().toInt(&) for t(1, T) var ss: [][]char :: cui@input().split(" ") var AA: int :: ss[0].toInt(&) var BB: int :: ss[1].toInt(&) var CC: int :: ss[2].toInt(&) var x: int :: ss[3].toInt(&) var y: int :: ss[4].toInt(&) var z: int :: ss[5].toInt(&) ; Bが最大のとき var ans1: int :: -1 block var A: int :: AA var B: int :: BB var C: int :: CC var cnt: int :: 0 ; x, yは、A=Cの時以外は使う必要がない。 if(A = C) if(x < y) do cnt :+ x do A :- 1 do B :- 1 else do cnt :+ y do C :- 1 do B :- 1 end if end if if(A > C) if(A >= B) do cnt :+ (A - (B - 1)) * z do C :- (A - (B - 1)) do A :- (A - (B - 1)) end if else if(C >= B) do cnt :+ (C - (B - 1)) * z do A :- (C - (B - 1)) do C :- (C - (B - 1)) end if end if if(A > 0 & C > 0 & B > 0) do ans1 :: cnt end if end block ; Bが最小のとき var ans2: int :: -1 block var A: int :: AA var B: int :: BB var C: int :: CC var cnt: int :: 0 if(B >= A) do cnt :+ (B - (A - 1)) * y do C :- (B - (A - 1)) do B :- (B - (A - 1)) end if if(B >= C) do cnt :+ (B - (C - 1)) * x do A :- (B - (C - 1)) do B :- (B - (C - 1)) end if if(A = C) if(x < y) do cnt :+ x do A :- 1 do B :- 1 else do cnt :+ y do B :- 1 do C :- 1 end if end if ;do cui@print("\{A} \{B} \{C}\n") if(A > 0 & C > 0 & B > 0) do ans2 :: cnt end if end block var ans: int :: -1 if(ans1 >= 0) do ans :: ans1 end if if(ans2 >= 0) if(ans >= 0) do ans :: lib@min(ans, ans2) else do ans :: ans2 end if end if do cui@print("\{ans}\n") end for end func