#P2374. Maximize Teacher's Effort
Maximize Teacher's Effort
Maximize Teacher's Effort
Professor Chen has three stacks of books placed on his desk. The three stacks contain , , and books respectively. In each stack, the books are arranged in a sequence from bottom to top (i.e. the input order gives the weight of books from bottom to top). To distribute the books to the students, he must remove all books from the stacks one by one. However, he can only remove the top book from any non‐empty stack at each step.
Each time he removes a book, his fatigue increases. The fatigue for the -th removed book is defined as the product of the book's weight and the fatigue factor . In other words, if a book of weight is removed as the -th book, the fatigue incurred in that move is .
As a prank, you want to make him work as hard as possible. Design a strategy to maximize the total fatigue cost required to remove all the books.
Formally, suppose the three stacks have , , and books respectively. Let , , and denote the lists of weights in the three stacks (each listed from bottom to top). At any moment, you may remove the top book from any stack. If the current move is the -th removal and you remove a book of weight , then the fatigue incurred is . Find the maximum possible total fatigue over all removals.
It is guaranteed that a valid removal order exists for all inputs.
inputFormat
The input consists of four lines:
- The first line contains three integers $i$, $j$, $k$, representing the number of books in the three stacks.
- The second line contains $i$ integers, representing the weights of the books in the first stack from bottom to top.
- The third line contains $j$ integers, representing the weights of the books in the second stack from bottom to top.
- The fourth line contains $k$ integers, representing the weights of the books in the third stack from bottom to top.
outputFormat
Output a single integer representing the maximum total fatigue the professor can incur by removing all the books in an optimal (i.e. most exhausting) order.
sample
1 1 1
1
2
3
14