Under construction

Still being built. Things may change

Chocolate

Time limit1sMemory limit128 MB

Summary
Find the minimum total cost to split an m by n chocolate bar into unit squares, where each vertical or horizontal cut costs a fixed price regardless of the piece size.
Level

Medium5 of 10

Topics
Greedy, Sorting
Solved
No attempts yet

Problem

We are given a bar of chocolate made up of m×nm \times n unit squares, and we want to break it into individual unit squares.

A part of the chocolate can be broken along one of its vertical or horizontal grid lines. A single break splits one part into two smaller parts. The cost of a break depends only on the line it is made along, not on the size of the part being broken. Breaking along vertical line ii costs xix_i (for i=1,2,…,m−1i = 1, 2, \ldots, m-1), and breaking along horizontal line jj costs yjy_j (for j=1,2,…,n−1j = 1, 2, \ldots, n-1).

For example, for the bar in the picture (m=6m = 6, n=4n = 4), if we first break along all horizontal lines and then break each resulting strip along the vertical lines, the total cost is y1+y2+y3+4⋅(x1+x2+x3+x4+x5)y_1 + y_2 + y_3 + 4 \cdot (x_1 + x_2 + x_3 + x_4 + x_5).

The total cost of breaking the whole bar into unit squares is the sum of the costs of all the breaks performed. Write a program that reads the values x1,x2,…,xm−1x_1, x_2, \ldots, x_{m-1} and y1,y2,…,yn−1y_1, y_2, \ldots, y_{n-1} and computes the minimum possible total cost of breaking the whole bar into unit squares.

Input

The first line contains two integers mm and nn separated by a single space (2≤m,n≤10002 \le m, n \le 1000).

Each of the next m−1m-1 lines contains one integer xix_i (1≤xi≤10001 \le x_i \le 1000), the cost of the ii-th vertical line.

Each of the following n−1n-1 lines contains one integer yjy_j (1≤yj≤10001 \le y_j \le 1000), the cost of the jj-th horizontal line.

Output

Print a single integer: the minimum total cost of breaking the whole bar into unit squares.

Examples3

  1. Example 1

    Input
    6 4
    2
    1
    3
    1
    4
    4
    1
    2
    
    Expected output
    42
    
  2. Example 2

    Input
    2 2
    1
    1
    
    Expected output
    3
    
  3. Example 3

    Input
    2 2
    1000
    1000
    
    Expected output
    3000