This page is still under construction.

Parts of this page are still being built. What you see may change.

Honey and Milk Land

Time limit1sMemory limit128 MB

Summary
Given spacings between parallel north-south rivers and between parallel east-west rivers, find the shortest helicopter route crossing every river at least once, rounded up.
Level

Medium6 of 10

Topics
Geometry, Greedy, Math, Implementation
Solved
No attempts yet

Problem

The Land of Honey and Milk is famous for its grid of milk rivers, and the government wants to inspect them every day so the milk never turns sour. The inspection is done by a helicopter: flying across a river at any single point is enough to inspect that whole river.

The rivers form two families, and all of them are straight. One family runs from North to South, the other runs from East to West. Within each family the rivers are parallel, and the distance between each pair of neighboring rivers is given. There are nn rivers running North–South and ee rivers running East–West.

The helicopter flies one continuous route and must cross every river at least once. You may choose the take-off and landing points freely. Every kilometer flown costs 1 honey barrel, the national currency; take-off and landing are free. Find the minimal cost of such a route.

Input

The first line contains two integers nn and ee (1≤n,e≤10001 \le n, e \le 1000).

The second line contains n−1n - 1 integers: the distances (in kilometers) between adjacent North–South rivers, listed from East to West.

The third line contains e−1e - 1 integers: the distances (in kilometers) between adjacent East–West rivers, listed from North to South.

The distance between any two adjacent rivers is at most 2727 kilometers. (If n=1n = 1 or e=1e = 1, the corresponding line contains no numbers.)

Output

Output the minimal cost of the route in honey barrels. Since there is no smaller denomination, print the smallest integer number of honey barrels that is sufficient to pay for the flight; that is, round the exact cost up to the next integer.

Examples3

  1. Example 1

    Input
    2 1
    1
    
    Expected output
    1
    
  2. Example 2

    Input
    10 10
    2 2 2 2 2 2 2 2 2
    2 2 2 2 2 2 2 2 2
    
    Expected output
    26
    
  3. Example 3

    Input
    1 1
    
    Expected output
    0