Minimize the Maximum Distance
Limits: 3 sec., 512 MiB
This problem is different from the problem "Maximize the Minimum Distance".
There are \(n \cdot m\) points on a two-dimensional plane, located in \(n\) rows and \(m\) columns.
The distance between the \(i\)-th and the \((i+1)\)-th row is \(a_i\).
The distance between the \(i\)-th and the \((i+1)\)-th column is \(b_i\).
You want to paint all the points in some colors. The number of colors that you can use is unlimited. However, the number of points for each color you use must be two or three.
Your goal is to minimize the maximum Euclidean distance between points of the same color. You only need to find the value of the sought distance and do not need to find the actual colors of the points.
Input
The first line contains two integers \(n\) and \(m\) – the number of rows and columns, respectively.
The second line contains \(n-1\) integers \(a_i\) – distances between the \(i\)-th and the \((i + 1)\)-th row.
The third line contains \(m-1\) integers \(b_i\) – distances between the \(i\)-th and the \((i + 1)\)-th column.
Output
In one line print a real number – the minimum possible maximum distance between points of the same color.
Your output will be considered correct if the absolute or relative error from the true answer is at most \(10^{-7}\).
Constraints
\(2 \le n, m \le 3 \cdot 10^5\),
\(1 \le a_i, b_i \le 10^9\).
Samples
Input (stdin) | Output (stdout) |
---|---|
2 3 1 4 1 | 1.0000000000 |
Input (stdin) | Output (stdout) |
---|---|
3 3 1 1 1 1 | 1.4142135624 |
Notes
Submit a solution
Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
---|
Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
---|