eolymp
bolt
Try our new interface for solving problems
Problems

Connected Gheeves

Connected Gheeves

Gheeves (plural of gheef) are some objects similar to funnels. We define a gheef as a two dimensional object specified by a sequence of points (\textbf{p_1}, \textbf{p_2}, ..., \textbf{p_n}) with the following conditions: \begin{itemize} \item \textbf{3} ≤ \textbf{n} ≤ \textbf{1000} \item If a point \textbf{p_i} is specified by the coordinates (\textbf{x_i}, \textbf{y_i}), there is an index \textbf{1} < \textbf{c} < \textbf{n} such that \textbf{y_1} > \textbf{y_2} > ... > \textbf{y_\{c \}}and \textbf{y_c} < \textbf{y_c_\{+1\}} < \textbf{y_c_\{+2\}} < ... < \textbf{y_n}. \textbf{p_c} is called the cusp of the gheef. \item For all \textbf{1} ≤ \textbf{i} < \textbf{c}, \textbf{x_i} < \textbf{x_c} and for all \textbf{c} < \textbf{i} ≤ \textbf{n}, \textbf{x_i} > \textbf{x_c}. \item For \textbf{1} < \textbf{i} < \textbf{c}, the amount of rotation required to rotate \textbf{p_i_\{-1\}} around \textbf{p_i} in clockwise direction to become co-linear with \textbf{p_i} and \textbf{p_i_\{+1\}}, is greater than \textbf{180} degrees. Likewise, for \textbf{c} < \textbf{i} < \textbf{n}, the amount of rotation required to rotate \textbf{p_i_\{-1\}} around \textbf{p_i} in clockwise rotation to become co-linear with \textbf{p_i} and \textbf{p_i_\{+1\}}, is greater than \textbf{180} degrees. \item The set of segments joining two consecutive points of the sequence intersect only in their endpoints. \end{itemize} For example, the following figure shows a gheef of six points with \textbf{c = 4}: \includegraphics{https://static.e-olymp.com/content/e4/e471c1cd1b6b7cf50bb9bd28b9d19b5d0286214d.jpg} We call the sequence of segments (\textbf{p_1p_2}, \textbf{p_2p_3}, ..., \textbf{p_n_\{-1\}p_n}), the body of the gheef. In this problem, we are given two gheeves \textbf{P} = (\textbf{p_1}, \textbf{p_2}, ..., \textbf{p_n}) and \textbf{Q} = (\textbf{q_1}, \textbf{q_2}, ..., \textbf{q_m}), such that all \textbf{x} coordinates of \textbf{p_i} are negative integers and all \textbf{x} coordinates of \textbf{q_i} are positive integers. Assuming the cusps of the two gheeves are connected with a narrow pipe, we pour a certain amount of water inside the gheeves. As we pour water, the gheeves are filled upwards according to known physical laws (the level of water in two gheeves remains the same). Note that in the gheef \textbf{P}, if the level of water reaches \textbf{min(y_1, y_n)}, the water pours out of the gheef (the same is true for the gheef \textbf{Q}). Your program must determine the level of water in the two gheeves after pouring a certain amount of water. Since we have defined our problem in two dimensions, the amount of water is measured in terms of area it fills. Note that the volume of pipe connecting cusps is considered as zero. \InputFile The first number in the input line, \textbf{t} is the number of test cases. Each test case is specified on three lines of input. The first line contains a single integer \textbf{a} (\textbf{1} ≤ \textbf{a} ≤ \textbf{100000}) which specifies the amount of water poured into two gheeves. The next two lines specify the two gheeves \textbf{P} and \textbf{Q} respectively, each of the form \textbf{k x_1 y_1 x_2 y_2 ... x_k y}_\{k \} where \textbf{k} is the number of points in the gheef (\textbf{n} for \textbf{P} and \textbf{m} for \textbf{Q}), and the \textbf{x_i y}_i sequence specify the coordinates of the points in the sequences. \OutputFile The output contains \textbf{t} lines, each corresponding to an input test case in that order. The output line contains a single integer \textbf{L} indicating the final level of water, expressed in terms of y coordinates rounded to three digits after decimal points.
Time limit 1 second
Memory limit 64 MiB
Input example #1
2
25
3 -30 10 -20 0 -10 10
3 10 10 20 0 30 10
25
3 -30 -10 -20 -20 -10 -10
3 10 10 20 0 30 10
Output example #1
3.536
-15.000