#P15077. [ICPC 2024 Chengdu R] Double 11

[ICPC 2024 Chengdu R] Double 11

题目描述

With the Double 11 Shopping Festival approaching, a store is managing its best-selling products for the event.

There are nn types of best-selling products, and the daily sales volume for each type is sis_i. Products need to be replenished multiple times to meet sales demand, and due to limited warehouse space, the total inventory must not exceed the storage capacity.

If only one type of product is replenished at a time, the workload becomes too high. To optimize replenishment, the store decides to divide the product types into mm groups, assigning a replenishment parameter to each group. For group jj, the replenishment parameter kjk_j is a positive real number, which means for each product type ii in this group, a volume of kjsik_j \cdot s_i will be prepared for each replenishment, and it will be replenished 1kj\frac{1}{k_j} times per day on average. Note that kjk_j can be either greater than, less than or equal to 11.

Let cic_i be the group index of product type ii. The maximum inventory in the warehouse can be represented by i=1nkcisi\sum_{i=1}^{n}{k_{c_i} \cdot s_i}. Due to the warehouse capacity limitation, this value cannot exceed 11.

Your task is to find a scheme that divides the nn product types into mm groups and assigns a replenishment parameter to each group such that the total number of replenishments per day is minimized while satisfying the warehouse capacity limitation, i.e., minimize i=1n1kci\sum_{i=1}^n{\frac{1}{k_{c_i}}}, subject to i=1nkcisi1\sum_{i=1}^{n}{k_{c_i} \cdot s_i} \le 1. For convenience, you should output the square root of the minimal answer, i.e., i=1n1kci\sqrt{\sum_{i=1}^n{\frac{1}{k_{c_i}}}}. Note that you can assign the same replenishment parameters to different groups.

输入格式

The first line contains two integers nn and mm (1mn21051 \le m \le n \le 2 \cdot 10^5), indicating the number of product types and the number of groups.

The second line contains nn integers sis_i (1si1051\le s_i \le 10^5), indicating the sales volume of product type ii.

输出格式

Output one real number, indicating the answer. Your output will be considered correct if the relative or absolute error does not exceed 10910^{-9}.

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

提示

For the first example, let $k_1=\frac{1}{3+\sqrt{21}}, k_2=\frac{1}{7+\sqrt{21}}$, and c1=c2=1,c3=c4=2c_1=c_2=1,c_3=c_4=2. We will get the maximum inventory as (1+2)k1+(3+4)k2=1(1+2)k_1 + (3+4)k_2 = 1, and the total number of replenishments is 2k1+2k2=20+421\frac{2}{k_1}+\frac{2}{k_2}=20+4\sqrt{21}. Therefore, the answer is 20+4216.1911471295571\sqrt{20+4\sqrt{21}} \approx 6.1911471295571, which is the minimum.