CF1666B.Budget Distribution

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nin_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 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 of the plan for the topic ii is defined as ∑j=1ni∣ci,jCi−pi,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 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,j≥0d_{i, j} \ge 0 and ∑i=1t∑j=1nidi,j=xk\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.

在资源有限且约束众多的情况下,合理分配预算资金是一项困难的任务。一个预算计划包含 tt 个主题;第 ii 个主题包含 nin_i 个项目。对于每个主题,其最优的相对资金分配比例已知。主题 ii 的最优相对分配是一组实数 pi,jp_{i,j},满足 ∑j=1nipi,j=1\sum\limits_{j=1}^{n_i}{p_{i,j}} = 1。

记分配给主题 ii 中第 jj 个项目的资金金额为 ci,jc_{i, j};该主题的总资金为 Ci=∑j=1nici,jC_i = \sum\limits_{j=1}^{n_i}{c_{i,j}}。主题 ii 的非最优性定义为 ∑j=1ni∣ci,jCi−pi,j∣\sum\limits_{j=1}^{n_i}\left|\frac{c_{i, j}}{C_i} - p_{i, j}\right|。直观上,该值表示该主题中所有项目实际资金占比与最优资金占比之间的总绝对偏差。整个预算计划的总非最优性即为所有 tt 个主题的非最优性之和。你的任务是使总非最优性最小化。

然而,当前尚不清楚可用资金的确切总额。第 ii 个主题中的第 jj 个项目目前已预先分配了 c^i,j\hat c_{i,j} 美元,且这部分资金不可收回。此外,尚有 qq 种可能的额外未分配资金数额 xkx_k。对每一个 xkx_k,你需要计算在将该额外资金以任意方式分配后所能达到的最小总非最优性。你无需将整数金额分配给项目(允许分配任意实数),但所有额外资金必须全部分配至各项目,即在已有 c^i,j\hat c_{i,j} 的基础上额外增加 di,jd_{i,j}。形式化地,对每个额外资金量 xkx_k,需找出一组分配量 di,jd_{i,j},满足 di,j≥0d_{i, j} \ge 0 且 ∑i=1t∑j=1nidi,j=xk\sum\limits_{i=1}^{t}\sum\limits_{j=1}^{n_i} d_{i,j} = x_k,使得最终预算分配 ci,j=c^i,j+di,jc_{i,j} = \hat c_{i,j} + d_{i,j} 所对应的总计划非最优性最小。

输入格式

The first line contains two integers tt (1≤t≤5⋅1041 \le t \le 5 \cdot 10^4) and qq (1≤q≤3⋅1051 \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 (2≤ni≤52 \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} (0≤c^i,j≤1050 \le \hat c_{i, j} \le 10^5; for any ii, at least one of c^i,j>0\hat c_{i,j} \gt 0) — the amount of money already assigned to jj-th item in ii-th topic; they are followed by nin_i integers pi,j′p'_{i,j} (1≤pi,j′≤10001 \le p'_{i,j} \le 1000) — they determine the values of pi,jp_{i,j} as pi,j=pi,j′/∑j=1nipi,j′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 (0≤xk≤10120 \le x_k \le 10^{12}) — kk-th possible amount of extra money.

第一行包含两个整数 tt(1≤t≤5⋅1041 \le t \le 5 \cdot 10^4)和 qq(1≤q≤3⋅1051 \le q \le 3 \cdot 10^5)——分别表示预算中主题的数量以及可能的额外资金数额的个数。

接下来的 tt 行描述各个主题。每行以一个整数 nin_i(2≤ni≤52 \le n_i \le 5)开头,表示第 ii 个主题中所含项目的数量;随后是 nin_i 个整数 c^i,j\hat c_{i, j}(0≤c^i,j≤1050 \le \hat c_{i, j} \le 10^5;对任意 ii,至少存在一个 jj 满足 c^i,j>0\hat c_{i,j} > 0),表示已分配给第 ii 个主题中第 jj 个项目的资金数额;再之后是 nin_i 个整数 pi,j′p'_{i,j}(1≤pi,j′≤10001 \le p'_{i,j} \le 1000),它们用于确定概率值 pi,jp_{i,j},具体定义为 pi,j=pi,j′/∑j=1nipi,j′p_{i, j} = {p'_{i, j}} \big/ {\sum\limits_{j=1}^{n_i}{p'_{i, j}}},其中满足 ∑j=1nipi,j=1\sum\limits_{j=1}^{n_i}{p_{i,j}} = 1。

下一行包含 qq 个整数 xkx_k(0≤xk≤10120 \le x_k \le 10^{12})——第 kk 个可能的额外资金数额。

输出格式

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 10−610^{-6}.

输出 qq 个实数——对应于额外资金量 xkx_k 的最小可能非最优性。答案的绝对误差或相对误差不得超过 10−610^{-6}。

输入输出样例

  • 输入#1

    1 5
    3 1 7 10 700 400 100
    0 2 10 50 102

    输出#1

    1.0555555555555556
    0.8666666666666667
    0.5476190476190478
    0.12745098039215708
    0.0
  • 输入#2

    2 5
    3 10 70 100 700 400 100
    3 10 30 100 700 400 100
    2 10 50 70 110

    输出#2

    2.2967032967032974
    2.216776340655188
    1.8690167362600323
    1.7301587301587305
    1.5271317829457367

输入解题思路,AI测评打分。不知道怎么写?

首页