Eating chocolate X32034


Statement
 

pdf   zip

Pau has a chocolate bar with n×mn \times m (1n,m1051 \leq n, m \leq 10^5) pieces and he wants to eat it.

In order to do so, Pau decides to apply the following procedure: he selects either a row or a column with at least one remaining piece and then he eats all the pieces that were left.

Each row and each column has a pleasure accumulator associated, indicating the number of pleasure units that Pau will obtain for each piece he eats if he selected that row or column. Considering all of this, compute the maximum amount of pleasure that Pau can achieve.

Input

The input contains several test cases. Each case begins with two integers nn and mm. A line follows containing nn numbers with the pleasure accumulators of the nn rows, then another line with mm numbers with the pleasure accumulators of the mm columns. Every pleasure accumulator is an integer number between 11 and 10410^4.

Output

For each case, print the maximum pleasure that can be achieved.

Public test cases
  • Input

    2 2
    1 2
    1 1
    4 3
    2 5 3 4
    1 5 1
    

    Output

    6
    48
    
  • Input

    2 2
    4 2
    3 1
    1 1
    10
    20

    Output

    13
    20
    
  • Information
    Author
    Félix Moreno
    Language
    English
    Translator
    Alex Alvarez
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++ Python
    User solutions
    C++ Python