eolymp
bolt
Try our new interface for solving problems
Problems

Icy Roads Of Nomel

Icy Roads Of Nomel

Do you think that driving is easy? This is not the case when the roads are covered with ice. The city of Nomel has exactly \textbf{N}+\textbf{1} streets (west-east roads) and \textbf{M}+\textbf{1} avenues (north-south roads). Each street intersects each avenue, so each street is divided into \textbf{M} blocks and each avenue is divided into \textbf{N} blocks. It's winter, and each road of the city is covered with a thick ice layer. As driving on ice is a bit tricky, each road has its own time of driving through one block of this road. This value is constant along all blocks of the road. Obviously, you can drive only through the roads. Now your task is to find a route from the north-western intersection of the city to the south-eastern one with the minimum driving time. This route must also be the shortest one, that is, it should pass through exactly \textbf{N}+\textbf{M} blocks. \InputFile The first line contains two integers \textbf{N} and \textbf{M} (\textbf{1} ≤ \textbf{N}, \textbf{M} ≤ \textbf{500 000}). The second line contains \textbf{N}+\textbf{1} positive integers representing the driving times of Nomel streets, given in the order from north to south. The third line contains \textbf{M}+\textbf{1 }positive integers representing the driving times of Nomel avenues, given in the order from west to east. It's guaranteed that none of these numbers exceed \textbf{10^9}. \OutputFile Print one integer - the required minimum total driving time.
Time limit 1 second
Memory limit 256 MiB
Input example #1
2 3
5 3 7
7 2 5 6
Output example #1
19
Author Gennady Korotkevich
Source Gennady Korotkevich Contest 1, Petrozavodsk Training Camp, Day 1, Friday, August 23, 2013