Chef and Universe
All submissions for this problem are available.
Read problems statements in Mandarin chinese, Russian andVietnamese as well.
Chef lives in the Universe in which only planets are present. Every planet is identified by 3 integers [p, q, r]. Chef lives on the planet [0, 0, 0] and wants to go to planet [X, Y, Z] with minimum energy loss.
The energy loss is determined by the following rules:
- If Chef goes from [p, q, r] to [p+1, q, r] or [p, q+1, r] or [p, q, r+1], then A units of energy are lost.
- If Chef goes from [p, q, r] to [p+1, q+1, r] or [p, q+1, r+1] or [p+1, q, r+1], then B units of energy are lost.
- If Chef goes from [p, q, r] to [p+1, q+1, r+1], then C units of energy are lost.
Your task is to calculate the minimum energy loss possible when Chef goes from planet [0, 0, 0] to planet [X, Y, Z].
- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- The only line of each test case contains 6 space-separated integers denoting the values of X, Y, Z, A, B and C respectively.
For each test case, output a single line containing one integer — the minimum energy loss.
- 1 ≤ T ≤ 105
- 1 ≤ X, Y, Z ≤ 105
- 1 ≤ A, B, C ≤ 103
Subtask #1 (20 points):
- 1 ≤ T ≤ 50
- 1 ≤ X, Y, Z ≤ 100
Subtask #2 (80 points): original constraints
Input: 2 1 2 3 10 1 5 2 2 1 1 2 3 Output: 3 5
Example case 1: One of the possible solutions is [0, 0, 0] --> [1, 0, 1] --> [1, 1, 2] --> [1, 2, 3]. The minimum energy loss is B + B + B = 3 · B = 3 · 1 = 3.
Example case 2: One of the possible solutions is [0, 0, 0] --> [1, 1, 1] --> [2, 2, 1]. The minimum energy loss is C + B = 3 + 2 = 5.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.