QOJ.ac

QOJ

时间限制: 6.0 s 内存限制: 1024 MB 总分: 100 可 Hack ✓

#9540. 双十一

统计

随着“双十一”购物节的临近,一家商店正在管理其热销产品。

商店共有 $n$ 种热销产品,每种产品的日销量为 $s_i$。为了满足销售需求,产品需要多次补货。由于仓库空间有限,总库存量不得超过存储容量。

如果一次只补货一种产品,工作量会过大。为了优化补货流程,商店决定将产品分为 $m$ 个组,并为每组分配一个补货参数。对于第 $j$ 组,补货参数 $k_j$ 是一个正实数,这意味着该组中的每种产品 $i$ 在每次补货时将准备 $k_j \cdot s_i$ 的量,且平均每天补货 $\frac{1}{k_j}$ 次。注意,$k_j$ 可以大于、小于或等于 1。

设 $c_i$ 为产品 $i$ 所属的组索引。仓库中的最大库存量可以表示为 $\sum_{i=1}^n k_{c_i} \cdot s_i$。由于仓库容量限制,该值不能超过 1。

你的任务是找到一种方案,将 $n$ 种产品分为 $m$ 个组,并为每组分配补货参数,使得在满足仓库容量限制的前提下,每天的总补货次数最小,即最小化 $\sum_{i=1}^n \frac{1}{k_{c_i}}$,且满足 $\sum_{i=1}^n k_{c_i} \cdot s_i \le 1$。为了方便起见,你应该输出最小答案的平方根,即 $\sqrt{\sum_{i=1}^n \frac{1}{k_{c_i}}}$。注意,你可以为不同的组分配相同的补货参数。

输入格式

第一行包含两个整数 $n$ 和 $m$ ($1 \le m \le n \le 2 \cdot 10^5$),分别表示产品种类数和组数。

第二行包含 $n$ 个整数 $s_i$ ($1 \le s_i \le 10^5$),表示产品 $i$ 的销量。

输出格式

输出一个实数,表示答案。如果你的输出与标准答案的相对误差或绝对误差不超过 $10^{-9}$,则被视为正确。

样例

输入 1

4 2
1 2 3 4

输出 1

6.1911471295571

输入 2

10 3
1 2 3 4 5 6 7 8 9 10

输出 2

22.5916253665141

说明

对于第一个样例,设 $k_1 = \frac{1}{3+\sqrt{21}}$,$k_2 = \frac{1}{7+\sqrt{21}}$,且 $c_1 = c_2 = 1$,$c_3 = c_4 = 2$。我们将得到最大库存为 $(1 + 2)k_1 + (3 + 4)k_2 = 1$,总补货次数为 $\frac{2}{k_1} + \frac{2}{k_2} = 20 + 4\sqrt{21}$。

因此,答案为 $\sqrt{20 + 4\sqrt{21}} \approx 6.1911471295571$,这是最小值。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.