eolymp
bolt
Try our new interface for solving problems

Corridor

The museum is closing right now and you still have one corridor to see. Under pressure of time, you decide not to miss the opportunity. The corridor does not contain any exhibits - it's the corridor itself that is the exhibit. If you look at it from above, it has two opposing walls, each forming a polygonal chain (a polygonal chain is a sequence of vertices connected by line segments). Looking at the plan of the corridor, you notice that in each chain the vertices' x coordinates are in (strictly) increasing order. Moreover, the first and the last vertices in that order are the only points where the two walls coincide - that's where the entrance and the exit are located. \includegraphics{https://static.e-olymp.com/content/a7/a72ee5c6c5df02073893d0e47f36f9ea5631f02d.jpg} In order to escape the guards who are going to be chasing you in a short while, calculate the length of the shortest path from the entrance to the exit. \InputFile The first line of input is an integer \textbf{T} - the number of test cases. \textbf{T} test cases follow. The first line of a test case contains a single integer \textbf{n_1} - the number of vertices in the upper polygonal chain. Each of the next \textbf{n_1} lines contains two integers \textbf{x_i}, \textbf{y_i} (|\textbf{x_i}|, |\textbf{y_i}| ≤ \textbf{10^9}) - the coordinates of the \textbf{i}-th vertex of the chain. The vertices are given in increasing order of \textbf{x} coordinates. After the description of the upper chain there is a line with a single integer \textbf{n_2}, followed by an analogous description of the lower wall. You may assume that \textbf{n_1} + \textbf{n_2} ≤ \textbf{200 000}. It is guaranteed that the upper wall is higher than the lower one along their full length except endpoints. \OutputFile For each test case, output the length of the shortest path linking the ends of the chains and situated between the two polygonal chains. Your answer should be accurate to within an absolute error of \textbf{10^\{-3\}} or a relative error of \textbf{10^\{-9\}}.
Zaman məhdudiyyəti 3 saniyə
Yaddaşı istafadə məhdudiyyəti 128 MiB
Giriş verilənləri #1
1
5
0 0
2 2
4 -1
5 1
6 0
5
0 0
1 -1
2 1
4 -2
6 0
Çıxış verilənləri #1
7.301
Mənbə 2013 Petrozavodsk Winter Training Camp, Jagiellonian University Contest, January 25, Problem C