Honey and Milk Land
Time limit1sMemory limit128 MB
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 rivers running North–South and 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 and ().
The second line contains integers: the distances (in kilometers) between adjacent North–South rivers, listed from East to West.
The third line contains 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 kilometers. (If or , 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.