A15035 | Budget Distribution
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Distributing budgeted money with limited resources and many constraints is a hard problem. A budget plan consists of $t$ topics; $i$ -th topic consists of $n_i$ items. For each topic, the optimal relative money distribution is known. The optimal relative distribution for the topic $i$ is a list of real numbers $p_{i,j}$ , where $\sum\limits_{j=1}^{n_i}{p_{i,j}} = 1$ .
Let's denote the amount of money assigned to $j$ -th item of the topic $i$ as $c_{i, j}$ ; the total amount of money for the topic is $C_i = \sum\limits_{j=1}^{n_i}{c_{i,j}}$ . A non-optimality of the plan for the topic $i$ 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 is the sum of non-optimalities of all $t$ topics. Your task is to minimize the total plan non-optimality.
However, the exact amount of money available is not known yet. $j$ -th item of $i$ -th topic already has $\hat c_{i,j}$ dollars assigned to it and they cannot be taken back. Also, there are $q$ possible values of the extra unassigned amounts of money available $x_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 $\hat c_{i,j}$ already assigned. Formally, for each value of extra money $x_k$ you'll need to find its distribution $d_{i,j}$ such that $d_{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 $c_{i,j} = \hat c_{i,j} + d_{i,j}$ that minimize the total plan non-optimality.
Let's denote the amount of money assigned to $j$ -th item of the topic $i$ as $c_{i, j}$ ; the total amount of money for the topic is $C_i = \sum\limits_{j=1}^{n_i}{c_{i,j}}$ . A non-optimality of the plan for the topic $i$ 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 is the sum of non-optimalities of all $t$ topics. Your task is to minimize the total plan non-optimality.
However, the exact amount of money available is not known yet. $j$ -th item of $i$ -th topic already has $\hat c_{i,j}$ dollars assigned to it and they cannot be taken back. Also, there are $q$ possible values of the extra unassigned amounts of money available $x_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 $\hat c_{i,j}$ already assigned. Formally, for each value of extra money $x_k$ you'll need to find its distribution $d_{i,j}$ such that $d_{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 $c_{i,j} = \hat c_{i,j} + d_{i,j}$ that minimize the total plan non-optimality.
输入格式
The first line contains two integers $t$ ( $1 \le t \le 5 \cdot 10^4$ ) and $q$ ( $1 \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 $t$ lines contain descriptions of topics. Each line starts with an integer $n_i$ ( $2 \le n_i \le 5$ ) — the number of items in $i$ -th topic; it is followed by $n_i$ integers $\hat c_{i, j}$ ( $0 \le \hat c_{i, j} \le 10^5$ ; for any $i$ , at least one of $\hat c_{i,j} > 0$ ) — the amount of money already assigned to $j$ -th item in $i$ -th topic; they are followed by $n_i$ integers $p'_{i,j}$ ( $1 \le p'_{i,j} \le 1000$ ) — they determine the values of $p_{i,j}$ as $p_{i, j} = {p'_{i, j}} \big/ {\sum\limits_{j=1}^{n_i}{p'_{i, j}}}$ with $\sum\limits_{j=1}^{n_i}{p_{i,j}} = 1$ .
The next line contains $q$ integers $x_k$ ( $0 \le x_k \le 10^{12}$ ) — $k$ -th possible amount of extra money.
The next $t$ lines contain descriptions of topics. Each line starts with an integer $n_i$ ( $2 \le n_i \le 5$ ) — the number of items in $i$ -th topic; it is followed by $n_i$ integers $\hat c_{i, j}$ ( $0 \le \hat c_{i, j} \le 10^5$ ; for any $i$ , at least one of $\hat c_{i,j} > 0$ ) — the amount of money already assigned to $j$ -th item in $i$ -th topic; they are followed by $n_i$ integers $p'_{i,j}$ ( $1 \le p'_{i,j} \le 1000$ ) — they determine the values of $p_{i,j}$ as $p_{i, j} = {p'_{i, j}} \big/ {\sum\limits_{j=1}^{n_i}{p'_{i, j}}}$ with $\sum\limits_{j=1}^{n_i}{p_{i,j}} = 1$ .
The next line contains $q$ integers $x_k$ ( $0 \le x_k \le 10^{12}$ ) — $k$ -th possible amount of extra money.
输出格式
Output $q$ real numbers — the minimal possible non-optimality for the corresponding amount of extra money $x_k$ . An absolute or a relative error of the answer must not exceed $10^{-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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted