CF1421D.Hexagons
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Lindsey Buckingham told Stevie Nicks "Go your own way". Nicks is now sad and wants to go away as quickly as possible, but she lives in a 2D hexagonal world.
Consider a hexagonal tiling of the plane as on the picture below.
Nicks wishes to go from the cell marked (0,0) to a certain cell given by the coordinates. She may go from a hexagon to any of its six neighbors you want, but there is a cost associated with each of them. The costs depend only on the direction in which you travel. Going from (0,0) to (1,1) will take the exact same cost as going from (−2,−1) to (−1,0) . The costs are given in the input in the order c1 , c2 , c3 , c4 , c5 , c6 as in the picture below.
Print the smallest cost of a path from the origin which has coordinates (0,0) to the given cell.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤104 ). Description of the test cases follows.
The first line of each test case contains two integers x and y ( −109≤x,y≤109 ) representing the coordinates of the target hexagon.
The second line of each test case contains six integers c1 , c2 , c3 , c4 , c5 , c6 ( 1≤c1,c2,c3,c4,c5,c6≤109 ) representing the six costs of the making one step in a particular direction (refer to the picture above to see which edge is for each value).
输出格式
For each testcase output the smallest cost of a path from the origin to the given cell.
输入输出样例
输入#1
2 -3 1 1 3 5 7 9 11 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
输出#1
18 1000000000000000000
说明/提示
The picture below shows the solution for the first sample. The cost 18 is reached by taking c3 3 times and c2 once, amounting to 5+5+5+3=18 .