Battlefield (Large)
Time limit5sMemory limit512 MB
You reorder your three weapon groups against the fixed enemy line to maximize the summed duel scores.
- Level
Medium7 of 10
- Topics
- Brute force, Math
- Solved
- No attempts yet
Problem
After the Third World War most modern technology was gone and only a few people survived. Humanity rebuilt slowly and started a new history. Thousands of years later, in a new medieval age, General Kim Yushin faced an enemy general on the battlefield.
Kim Yushin commands officers. of them carry weapon 1, carry weapon 2, and carry weapon 3. They stand side by side in one long line on a hill, looking at the enemy camp.
The enemy general also commands officers. of them carry weapon 4, carry weapon 5, and carry weapon 6. They form one line on the opposite hill and prepare to hold off the attack.
Once the battle starts, the two lines face each other in the order they stand, and each pair fights one on one. Before giving the order to attack, Kim Yushin can rearrange his own line in any order he likes.
You are given the integers , , , , , , , , . is the result of the duel when an officer of Kim Yushin carrying weapon meets an enemy officer carrying weapon . A positive value means a result in Kim Yushin's favor.
The result of the whole battle is the sum of the results of the single duels. Find the largest total battle result Kim Yushin can reach by rearranging his line.
Input
The first line contains the number of test cases . Each test case is given on the following four lines.
N A B C D E F
P14 P15 P16
P24 P25 P26
P34 P35 P36
Constraints
- All values are integers.
Output
For each test case, print one line in the form Case #x: y, where is the test case number starting from 1 and is the largest total battle result Kim Yushin can reach.