Revenue

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

문제

There is a seller who has nn items for sale to a single buyer. The buyer has a valuation profile vˉ=(v_1,,v_n)\bar{v} = (v\_1, \ldots, v\_n), where v_j0v\_j \ge 0 denotes her value for item jj.

The seller can set a pricing pˉ\bar{p}, that is, a vector of item prices (p_1,,p_n)(p\_1, \ldots, p\_n). Given a pricing pˉ\bar{p}, the utility of buying item jj is v_jp_jv\_j - p\_j. The buyer will purchase a single item jj that maximizes her utility, or nothing if her utility from purchasing any item would be negative. If there are multiple items with the same maximal utility, she will choose the one with the minimal price. The revenue of the seller is defined as the price of the item that the buyer buys, and if the buyer buys nothing, the revenue is 00.

Now we know that the valuation profile vˉ\bar{v} is drawn from a joint distribution FF which defines the probability of every possible value of vˉ\bar{v}. Unfortunately, we do not know FF. Instead, we know the marginal distributions F_1,F_2,,F_nF\_1, F\_2, \ldots, F\_n: distribution F_iF\_i defines the probability of v_i=xv\_i = x for every possible xx. But we do not know how they are correlated: the values are not necessarily independent, so the individual probabilities of v_i=xv\_i = x and v_j=yv\_j = y don't define the probability of both happening simultaneously. Note that the joint distribution FF is over the valuation profile vˉ\bar{v} and that the marginal distribution F_iF\_i is over the value v_iv\_i of item ii.

Given the pricing pˉ\bar{p} and the marginal distributions F_1,F_2,,F_nF\_1, F\_2, \ldots, F\_n, we are now asked to compute the minimal expected revenue among all possible joint distributions. Formally, let F\mathcal{F} be the set of joint distributions over valuation profiles vˉ\bar{v} whose marginal distributions for the individual item values are just F_1,F_2,,F_nF\_1, F\_2, \ldots, F\_n. Let Rev(pˉ,F)\mathrm{Rev} (\bar{p}, F) be the seller's expected revenue from setting a pricing pˉ\bar{p}, if the valuation profile vˉ\bar{v} is drawn from a joint distribution FF. We are asked to compute min_FFRev(pˉ,F).\min\_{F \in \mathcal{F}} \mathrm{Rev}(\bar{p}, F)\text{.}

입력

The first line contains a single integer nn (1n1051 \le n \le 10^5), the number of items for sale.

The second line contains nn non-negative integers p_1,p_2,,p_np\_1, p\_2, \ldots, p\_n (0p_i1050 \le p\_i \le 10^5), the pricing vector pˉ\bar{p}.

Next nn lines describe the marginal distributions F_1,F_2,,F_nF\_1, F\_2, \ldots, F\_n. Each line starts with an integer kk: the support size (number of different values) of F_iF\_i. Then follow kk pairs of numbers q_jq\_{j} and v_jv\_{j} (0q_j10 \le q\_{j} \le 1, 0v_j1060 \le v\_{j} \le 10^6), meaning that F_iF\_i has probability of q_jq\_{j} to have value v_jv\_{j}. The values v_jv\_{j} may be given as decimal fractions or in scientific notation. It is guaranteed that _j=1kq_j=1\sum\_{j = 1}^{k} q\_{j} = 1.

The total sum of the values of kk on these nn lines will not exceed 31053 \cdot 10^5. The total size of the input will not exceed 55 mebibytes.

출력

Output a single real number: the minimal expected revenue among all possible joint distributions. Your answer will be considered correct if and only if its absolute or relative error does not exceed 10610^{-6}.