This page is still under construction.

Parts of this page are still being built. What you see may change.

Line Fitting Under Uncertainty

Time limit2sMemory limit256 MB

Summary
Find the line that minimizes the worst expected absolute deviation from uncertain sample values and print that error.
Level

Hard8 of 10

Topics
Binary search, Geometry, Math
Solved
No attempts yet

Problem

Fitting a function to a finite set of points sampled from an unknown function F:R→RF : \mathbb{R} \to \mathbb{R} is a basic problem in mathematics. The most common form is to find a linear function F‾\overline{F} that fits the sampled points best. Suppose FF is sampled at x1<x2<⋯<xnx_1 < x_2 < \dots < x_n. One way to measure how well F‾\overline{F} fits the sample points is the error

error(F,F‾)=max⁡1≤i≤n∣F(xi)−F‾(xi)∣\text{error}(F, \overline{F}) = \max_{1 \le i \le n} \left| F(x_i) - \overline{F}(x_i) \right|

The function values at the sample points are not known exactly. Instead you have a discrete probability distribution for each F(xi)F(x_i): a list of possible values yi,1,…,yi,miy_{i,1}, \dots, y_{i,m_i} with probabilities pi,jp_{i,j} such that Pr⁡[F(xi)=yi,j]=pi,j\Pr[F(x_i) = y_{i,j}] = p_{i,j}. The error is then defined with expected values.

error(F,F‾)=max⁡1≤i≤nE[∣F(xi)−F‾(xi)∣]\text{error}(F, \overline{F}) = \max_{1 \le i \le n} E\left[ \left| F(x_i) - \overline{F}(x_i) \right| \right]

Write a program that finds the linear function F‾(x)=ax+b\overline{F}(x) = ax + b minimizing this error and reports the minimum error.

Input

The input holds several test cases. The first line of each test case contains nn, the number of sample points (1≤n≤1051 \le n \le 10^5). The next nn lines describe the sample points in increasing order of xx, one line per point. The line for the ii-th sample point starts with the position xix_i at which the function is sampled and the size mim_i of its distribution (0≤xi≤1090 \le x_i \le 10^9, 1≤mi≤101 \le m_i \le 10). Then come the mim_i possible function values at xix_i, yi,1,…,yi,miy_{i,1}, \dots, y_{i,m_i} (0≤yi,j<1090 \le y_{i,j} < 10^9), followed by the mim_i probabilities pi,1,…,pi,mip_{i,1}, \dots, p_{i,m_i} (0≤pi,j≤1000 \le p_{i,j} \le 100). The real probability is pi,jp_{i,j} divided by 100, and for each sample point the mim_i probability numbers add up to 100. All values are integers and x1<x2<⋯<xnx_1 < x_2 < \dots < x_n. The last line of the input contains a single 0, which is not a test case.

Output

For each test case, print one line with the minimum error, rounded to exactly one digit after the decimal point. Round a value exactly halfway up, so 0.25 prints as 0.3.

Examples2

  1. Example 1

    Input
    2
    0 2 0 1 50 50
    1 2 0 1 50 50
    0
    
    Expected output
    0.5
    
  2. Example 2

    Input
    1
    5 1 7 100
    1
    5 2 0 10 50 50
    3
    0 1 1 100
    1 1 3 100
    2 1 5 100
    0
    
    Expected output
    0.0
    5.0
    0.0