CF BUDDY
← Problems·

1491B · Minimal Cost

1200 · brute force, math

Problem: There is a graph of nn rows and 106+210^6 + 2 columns, where rows are numbered from 11 to nn and columns from 00 to 106+110^6 + 1:

Let's denote the node in the row ii and column jj by (i,j)(i, j).

Initially for each ii the ii-th row has exactly one obstacle — at node (i,ai)(i, a_i). You want to move some obstacles so that you can reach node (n,106+1)(n, 10^6+1) from node (1,0)(1, 0) by moving through edges of this graph (you can't pass through obstacles). Moving one obstacle to an adjacent by edge free node costs uu or vv coins, as below:

  • If there is an obstacle in the node (i,j)(i, j), you can use uu coins to move it to (i1,j)(i-1, j) or (i+1,j)(i+1, j), if such node exists and if there is no obstacle in that node currently.
  • If there is an obstacle in the node (i,j)(i, j), you can use vv coins to move it to (i,j1)(i, j-1) or (i,j+1)(i, j+1), if such node exists and if there is no obstacle in that node currently.
  • Note that you can't move obstacles outside the grid. For example, you can't move an obstacle from (1,1)(1,1) to (0,1)(0,1).

Refer to the picture above for a better understanding.

Now you need to calculate the minimal number of coins you need to spend to be able to reach node (n,106+1)(n, 10^6+1) from node (1,0)(1, 0) by moving through edges of this graph without passing through obstacles.

Input Format: The first line contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains three integers nn, uu and vv (2n1002 \le n \le 100, 1u,v1091 \le u, v \le 10^9) — the number of rows in the graph and the numbers of coins needed to move vertically and horizontally respectively.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1061 \le a_i \le 10^6) — where aia_i represents that the obstacle in the ii-th row is in node (i,ai)(i, a_i).

It's guaranteed that the sum of nn over all test cases doesn't exceed 21042 \cdot 10^4.

Output Format: For each test case, output a single integer — the minimal number of coins you need to spend to be able to reach node (n,106+1)(n, 10^6+1) from node (1,0)(1, 0) by moving through edges of this graph without passing through obstacles.

It can be shown that under the constraints of the problem there is always a way to make such a trip possible.

Note: In the first sample, two obstacles are at (1,2)(1, 2) and (2,2)(2,2). You can move the obstacle on (2,2)(2, 2) to (2,3)(2, 3), then to (1,3)(1, 3). The total cost is u+v=7u+v = 7 coins.

In the second sample, two obstacles are at (1,3)(1, 3) and (2,2)(2,2). You can move the obstacle on (1,3)(1, 3) to (2,3)(2, 3). The cost is u=3u = 3 coins.

Sample Cases

Case 1

Input

3
2 3 4
2 2
2 3 4
3 2
2 4 3
3 2

Output

7
3
3

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback