Hide

Problem M
Sequence Discrepancy

/problems/vths21.sequencediscrepancy/file/statement/en/img-0001.png

Bob has recently been working on developing some new random number generators. In particular, he wants his random number generators to be able to generate points in the unit square. Unfortunately, Bob is having some trouble measuring how good his different generators are, so he’s asked for your help to implement one such measure.

One test often used to measure the randomness of a generator is by measuring its discrepancy. In particular, given a sequence of points $P=\{ (x_1, y_1), (x_2, y_2), \dots , (x_ n, y_ n)\} $ in the unit square, the discrepancy of the sequence with respect to a rectangle $R=[0, v_1]\times [0, v_2]$ is the absolute difference between the area of the rectangle $R$ and the proportion of the points $(x_ i, y_ i)$ that are in $R$. Mathematically, we can write this as

\[ D(P, R)=\left|\frac{\sharp \{ (x_ i, y_ i)\in R\} }{n} - A(R) \right| \]

where $A(R)$ is the area of the rectangle $R$ and $\sharp \{ (x_ i, y_ i)\in R\} $ is the number of points in $R$.

Finally, given a set of rectangles whose lower left corner is $(0, 0)$, the discrepancy of the sequence $P$ with respect to the set of rectangles is the maximum discrepancy of any rectangle in the set.

Your task is to compute this discrepancy for a sequence of points and set of rectangles that Bob gives you.

Input

The input consists of a single test case. The first line contains two integers $n$ and $m$ ($1\leq n\leq 1\, 000$, $1\leq m\leq 1\, 000$) separated by a space, where $n$ is the number of points in the sequence and $m$ is the number of rectangles.

This is followed by $n$ lines, each containing two real numbers $x$ and $y$ ($0\leq x, y\leq 1$) representing a point in the sequence.

Finally, the input will end with $m$ lines each containing two real numbers $x$ and $y$ ($0\leq x, y\leq 1$) representing the upper right corner $(x, y)$ of a rectangle whose lower left corner is at the origin $(0, 0)$.

Output

Output the discrepancy of the sequence with respect to the set of rectangles. Your answer will be considered correct if it is within $10^{-6}$ of the correct answer.

Sample Input 1 Sample Output 1
2 2
0.5 0.5
0.8 0.8
0.4 0.4
1.0 1.0
0.16
Sample Input 2 Sample Output 2
4 4
0.25 0.25
0.7 0.25
0.4 0.9
0.9 0.7
0.3 0.3
0.5 1
1 0.5
0.9 0.9
0.19

Please log in to submit a solution to this problem

Log in