QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 100

#12977. Chocolate

الإحصائيات

We are given a bar of chocolate composed of $m \times n$ square pieces. One should break the chocolate into single squares. Parts of the chocolate may be broken along the vertical and horizontal lines as indicated by the broken lines in the picture. A single break of a part of the chocolate along a chosen vertical or horizontal line divides that part into two smaller ones. Each break of a part of the chocolate is charged a cost expressed by a positive integer. This cost does not depend on the size of the part that is being broken but only depends on the line the break goes along. Let us denote the costs of breaking along consecutive vertical lines with $x_1,x_2,…,x_{m-1}$ and along horizontal lines with $y_1,y_2,…,y_{n-1}$. The cost of breaking the whole bar into single squares is the sum of the successive breaks. One should compute the minimal cost of breaking the whole chocolate into single single squares.

problem_12977_1.jpg

For example, if we break the chocolate presented in the picture first along the horizontal lines, and next each obtained part along vertical lines then the cost of that breaking will be $y_1+y_2+y_3+4 \cdot (x_1+x_2+x_3+x_4+x_5)$.

Write a program which:

  • reads the numbers $x_1,x_2,…,x_{m-1}$ and $y_1,y_2,…,y_{n-1}$,
  • computes the minimal cost of breaking the whole chocolate into single squares,
  • writes the result.

Input

In the first line of the standard input there are two positive integers $m$ and $n$ separated by a single space, $2 ≤ m,n ≤ 1\,000$. In the successive $m-1$ lines there are numbers $x_1,x_2,…,x_{m-1}$, one per line, $1 ≤ x_i ≤ 1\,000$. In the successive $n-1$ lines there are numbers $y_1,y_2,…,y_{n-1}$, one per line, $1 ≤ y_i ≤ 1\,000$.

Output

Your program should write to the standard output. In the first and only line your program should write one integer - the minimal cost of breaking the whole chocolate into single squares.

Example

Input

6 4
2
1
3
1
4
4
1
2

Output

42
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.