Gahee and Sajik Stadium
Time limit1sMemory limit512 MB
Place N idols on an R by C grid to maximize total charm, counting each cell's charm and the extra charm for adjacent Three Musketeers pairs.
- Level
Hard8 of 10
- Topics
- Graph, Brute force
- Solved
- No attempts yet
Problem
Gahee wants to place idols on the stage of Sajik Stadium, the home ground of the Lotte Giants, which she supports. The stage has rows and columns. Each idol has a number from 1 to . Three of the idols are called the Three Musketeers. When the three are adjacent to each other horizontally, vertically, or diagonally, they produce a special effect. Gahee wants to place the idols on the stage to maximize their total charm. Tell her how to do it.
Input
The first line has , , and separated by spaces. The second line has the numbers of the Three Musketeers, , , and , separated by spaces. The third line has the extra charm gained when idol and idol are adjacent, when idol and idol are adjacent, and when idol and idol are adjacent, separated by spaces. The next lines each have numbers separated by spaces. The -th number on the -th line is the charm gained when an idol stands at row , column .
Output
Print the maximum total charm that Gahee can obtain when she places all idols on the stage.
Constraints
. . . . Each charm value at a point on the stage is between 1 and . , , and are all different integers between 1 and . The extra charm for each adjacent pair among the Three Musketeers is an integer between 1 and .