Counterattack
InterviewTime limit1sMemory limit256 MB
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 marked points numbered through , and at every step both strikers stand at their own point of the same index. Whenever the striker in possession is at point with , they must choose one of two moves:
- Dribble to their own point .
- Pass to the other striker's point .
At the last point , 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:
- The defender's long pass, placing the ball on striker 1's point (difficulty ) or striker 2's point (difficulty ).
- A sequence of dribbles and passes that advances the ball from point to point until it reaches point .
- A shot at point , taken by striker 1 (difficulty ) or striker 2 (difficulty ).
Assuming WeissBlume FC plays ideally, compute the minimum possible total difficulty to score.
Input
The first line contains the number of test cases (). Each test case consists of five lines.
The first line of a test case contains , , , , . Here () is the number of marked points on each route, and are the difficulties of the defender's long pass to striker 1 and striker 2, and and are the difficulties of a shot by striker 1 and striker 2.
The second line contains integers; the -th is the difficulty of striker 1 passing from their point to striker 2's point .
The third line contains integers; the -th is the difficulty of striker 1 dribbling from their point to their own point .
The fourth line contains integers; the -th is the difficulty of striker 2 passing from their point to striker 1's point .
The fifth line contains integers; the -th is the difficulty of striker 2 dribbling from their point to their own point .
Every difficulty is a non-negative integer not greater than .
Output
For each test case, print a single line containing the minimum total difficulty required to score.