Budget Distribution

아직 제출이 없습니다시간 제한3초메모리 제한512 MB

문제

Distributing budgeted money with limited resources and many constraints is a hard problem. A budget plan consists of tt topics; ii-th topic consists of n_in\_i items. For each topic, the optimal relative money distribution is known. The optimal relative distribution for the topic ii is a list of real numbers p_i,jp\_{i,j}, where _j=1n_ip_i,j=1\sum\limits\_{j=1}^{n\_i}{p\_{i,j}} = 1.

Let's denote the amount of money assigned to jj-th item of the topic ii as c_i,jc\_{i, j}; the total amount of money for the topic is C_i=_j=1n_ic_i,jC\_i = \sum\limits\_{j=1}^{n\_i}{c\_{i,j}}. A non-optimality of the plan for the topic ii is defined as _j=1n_ic_i,jC_ip_i,j\sum\limits\_{j=1}^{n\_i}\left|\frac{c\_{i, j}}{C\_i} - p\_{i, j}\right|. Informally, the non-optimality is the total difference between the optimal and the actual ratios of money assigned to all the items in the topic. The total plan non-optimality is the sum of non-optimalities of all tt topics. Your task is to minimize the total plan non-optimality.

However, the exact amount of money available is not known yet. jj-th item of ii-th topic already has c^_i,j\hat c\_{i,j} dollars assigned to it and they cannot be taken back. Also, there are qq possible values of the extra unassigned amounts of money available x_kx\_k. For each of them, you need to calculate the minimal possible total non-optimality among all ways to distribute this extra money. You don't need to assign an integer amount of money to an item, any real number is possible, but all the extra money must be distributed among all the items in addition to c^_i,j\hat c\_{i,j} already assigned. Formally, for each value of extra money x_kx\_k you'll need to find its distribution d_i,jd\_{i,j} such that d_i,j0d\_{i, j} \ge 0 and _i=1t_j=1n_id_i,j=x_k\sum\limits\_{i=1}^{t}\sum\limits\_{j=1}^{n\_i} d\_{i,j} = x\_k, giving the resulting budget assignments c_i,j=c^_i,j+d_i,jc\_{i,j} = \hat c\_{i,j} + d\_{i,j} that minimize the total plan non-optimality.

입력

The first line contains two integers tt (1t51041 \le t \le 5 \cdot 10^4) and qq (1q31051 \le q \le 3 \cdot 10^5) --- the number of topics in the budget and the number of possible amounts of extra money.

The next tt lines contain descriptions of topics. Each line starts with an integer n_in\_i (2n_i52 \le n\_i \le 5) --- the number of items in ii-th topic; it is followed by n_in\_i integers c^_i,j\hat c\_{i, j} (0c^_i,j1050 \le \hat c\_{i, j} \le 10^5; for any ii, at least one of c^_i,j>0\hat c\_{i,j} > 0) --- the amount of money already assigned to jj-th item in ii-th topic; they are followed by n_in\_i integers p_i,jp'\_{i,j} (1p_i,j10001 \le p'\_{i,j} \le 1000) --- they determine the values of p_i,jp\_{i,j} as p_i,j=p_i,j/_j=1n_ip_i,jp\_{i, j} = {p'\_{i, j}} \big/ {\sum\limits\_{j=1}^{n\_i}{p'\_{i, j}}} with _j=1n_ip_i,j=1\sum\limits\_{j=1}^{n\_i}{p\_{i,j}} = 1.

The next line contains qq integers x_kx\_k (0x_k10120 \le x\_k \le 10^{12}) --- kk-th possible amount of extra money.

출력

Output qq real numbers --- the minimal possible non-optimality for the corresponding amount of extra money x_kx\_k. An absolute or a relative error of the answer must not exceed 10610^{-6}.