There is a shop in your city, in which matches of different integer thicknesses from 1 to N, inclusive, are sold. All matches in the shop have the same length. The (i-1)-th element of **cost** is the cost of one match with thickness i.
You wish to buy some matches and use them to construct a 2xM rectangle. For example, if M=5, then the rectangle will look as follows (characters '|' and '-' correspond to matches):
_ _ _ _ _
| | | | | |
_ _ _ _ _
| | | | | |
_ _ _ _ _
You are given two int[]s, **top** and **bottom**, each containing exactly M elements. **top** and **bottom** contain the required thicknesses of the squares in the top and bottom rows of the rectangle, respectively, from left to right. The thickness of a square is the sum of the thicknesses of its four sides. Return the minimum total cost of matches needed to construct the required rectangle, or -1 if it's not possible. |