#P12815. [NERC 2021] Budget Distribution

    ID: 12595 Type: RemoteJudge 3000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>2021Special JudgeICPCNERC/NEERC

[NERC 2021] Budget Distribution

题目描述

Distributing budgeted money with limited resources and many constraints is a hard problem. A budget plan\textit{budget plan} consists of tt topics; ii-th topic consists of nin_i items. For each topic, the optimal relative money distribution\textit{optimal relative money distribution} is known. The optimal relative distribution for the topic ii is a list of real numbers pi,jp_{i,j}, where j=1nipi,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 ci,jc_{i, j}; the total amount of money for the topic is Ci=j=1nici,jC_i = \sum\limits_{j=1}^{n_i}{c_{i,j}}. A non-optimality\textit{non-optimality} of the plan for the topic ii is defined as $\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\textit{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 xkx_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 xkx_k you'll need to find its distribution di,jd_{i,j} such that di,j0d_{i, j} \ge 0 and $\sum\limits_{i=1}^{t}\sum\limits_{j=1}^{n_i} d_{i,j} = x_k$, giving the resulting budget assignments ci,j=c^i,j+di,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 nin_i (2ni52 \le n_i \le 5) --- the number of items in ii-th topic; it is followed by nin_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 nin_i integers pi,jp'_{i,j} (1pi,j10001 \le p'_{i,j} \le 1000) --- they determine the values of pi,jp_{i,j} as $p_{i, j} = {p'_{i, j}} \big/ {\sum\limits_{j=1}^{n_i}{p'_{i, j}}}$ with j=1nipi,j=1\sum\limits_{j=1}^{n_i}{p_{i,j}} = 1.

The next line contains qq integers xkx_k (0xk10120 \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 xkx_k. An absolute or a relative error of the answer must not exceed 10610^{-6}.

1 5
3 1 7 10 700 400 100
0 2 10 50 102
1.0555555555555556
0.8666666666666667
0.5476190476190478
0.12745098039215708
0.0
2 5
3 10 70 100 700 400 100
3 10 30 100 700 400 100
2 10 50 70 110
2.2967032967032974
2.216776340655188
1.8690167362600323
1.7301587301587305
1.5271317829457367