There is a seller who has n items for sale to a single buyer. The buyer has a valuation profile vˉ=(v_1,…,v_n), where v_j≥0 denotes her value for item j.
The seller can set a pricing pˉ, that is, a vector of item prices (p_1,…,p_n). Given a pricing pˉ, the utility of buying item j is v_j−p_j. The buyer will purchase a single item j 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 0.
Now we know that the valuation profile vˉ is drawn from a joint distribution F which defines the probability of every possible value of vˉ. Unfortunately, we do not know F. Instead, we know the marginal distributions F_1,F_2,…,F_n: distribution F_i defines the probability of v_i=x for every possible x. But we do not know how they are correlated: the values are not necessarily independent, so the individual probabilities of v_i=x and v_j=y don't define the probability of both happening simultaneously. Note that the joint distribution F is over the valuation profile vˉ and that the marginal distribution F_i is over the value v_i of item i.
Given the pricing pˉ and the marginal distributions F_1,F_2,…,F_n, we are now asked to compute the minimal expected revenue among all possible joint distributions. Formally, let F be the set of joint distributions over valuation profiles vˉ whose marginal distributions for the individual item values are just F_1,F_2,…,F_n. Let Rev(pˉ,F) be the seller's expected revenue from setting a pricing pˉ, if the valuation profile vˉ is drawn from a joint distribution F. We are asked to compute min_F∈FRev(pˉ,F).
The first line contains a single integer n (1≤n≤105), the number of items for sale.
The second line contains n non-negative integers p_1,p_2,…,p_n (0≤p_i≤105), the pricing vector pˉ.
Next n lines describe the marginal distributions F_1,F_2,…,F_n. Each line starts with an integer k: the support size (number of different values) of F_i. Then follow k pairs of numbers q_j and v_j (0≤q_j≤1, 0≤v_j≤106), meaning that F_i has probability of q_j to have value v_j. The values v_j may be given as decimal fractions or in scientific notation. It is guaranteed that ∑_j=1kq_j=1.
The total sum of the values of k on these n lines will not exceed 3⋅105. The total size of the input will not exceed 5 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 10−6.