#P2374. Maximize Teacher's Effort

    ID: 15646 Type: Default 1000ms 256MiB

Maximize Teacher's Effort

Maximize Teacher's Effort

Professor Chen has three stacks of books placed on his desk. The three stacks contain ii, jj, and kk 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 mm-th removed book is defined as the product of the book's weight and the fatigue factor mm. In other words, if a book of weight ww is removed as the mm-th book, the fatigue incurred in that move is m×wm \times w.

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 ii, jj, and kk books respectively. Let AA, BB, and CC 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 mm-th removal and you remove a book of weight ww, then the fatigue incurred is m×wm \times w. 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:

  1. The first line contains three integers $i$, $j$, $k$, representing the number of books in the three stacks.
  2. The second line contains $i$ integers, representing the weights of the books in the first stack from bottom to top.
  3. The third line contains $j$ integers, representing the weights of the books in the second stack from bottom to top.
  4. 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