Under construction

Still being built. Things may change

Counterattack

Interview

Time limit1sMemory limit256 MB

Summary
Two strikers advance in lockstep through n points, each step either dribbling or passing to the partner; find the cheapest route from a long pass at point 1 to a shot at point n.
Level

Medium5 of 10

Topics
Dynamic programming, Array, Implementation
Solved
No attempts yet

Problem

Counterattacks are a crucial tactic in soccer. When WeissBlume FC defends, everyone except two strikers stays back in their own half. The instant a defender wins the ball, they launch a long pass to one of the two strikers and the counterattack begins.

Both strikers run along fixed, synchronized routes. Each route has the same nn marked points numbered 11 through nn, and at every step both strikers stand at their own point of the same index. Whenever the striker in possession is at point ii with i<ni < n, they must choose one of two moves:

  • Dribble to their own point i+1i+1.
  • Pass to the other striker's point i+1i+1.

At the last point nn, the striker in possession shoots.

Each of the four possible actions (long pass, dribble, pass, shot) can fail, so the coach assigned every action a difficulty. One full counterattack is:

  1. The defender's long pass, placing the ball on striker 1's point 11 (difficulty l1l_1) or striker 2's point 11 (difficulty l2l_2).
  2. A sequence of dribbles and passes that advances the ball from point ii to point i+1i+1 until it reaches point nn.
  3. A shot at point nn, taken by striker 1 (difficulty s1s_1) or striker 2 (difficulty s2s_2).

Assuming WeissBlume FC plays ideally, compute the minimum possible total difficulty to score.

Input

The first line contains the number of test cases cc (1≤c≤1001 \le c \le 100). Each test case consists of five lines.

The first line of a test case contains nn, l1l_1, l2l_2, s1s_1, s2s_2. Here nn (2≤n≤1000002 \le n \le 100000) is the number of marked points on each route, l1l_1 and l2l_2 are the difficulties of the defender's long pass to striker 1 and striker 2, and s1s_1 and s2s_2 are the difficulties of a shot by striker 1 and striker 2.

The second line contains n−1n-1 integers; the ii-th is the difficulty of striker 1 passing from their point ii to striker 2's point i+1i+1.

The third line contains n−1n-1 integers; the ii-th is the difficulty of striker 1 dribbling from their point ii to their own point i+1i+1.

The fourth line contains n−1n-1 integers; the ii-th is the difficulty of striker 2 passing from their point ii to striker 1's point i+1i+1.

The fifth line contains n−1n-1 integers; the ii-th is the difficulty of striker 2 dribbling from their point ii to their own point i+1i+1.

Every difficulty is a non-negative integer not greater than 10001000.

Output

For each test case, print a single line containing the minimum total difficulty required to score.

Examples2

  1. Example 1

    Input
    2
    3 3 5 7 999
    9 13
    60 5
    22 6
    5 5
    5 3 5 7 999
    9 13 8 4
    60 5 17 13
    22 6 15 11
    5 5 18 29
    
    Expected output
    23
    42
    
  2. Example 2

    Input
    1
    2 1 100 1 100
    0
    0
    0
    0
    
    Expected output
    2