QOJ.ac

QOJ

حد الوقت: 2.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100

#17157. 房子

الإحصائيات

Byteasar 想要建造一座木屋。他有 $n$ 根长度分别为 $a_1, \dots, a_n$ 且高度相同的木材。这些木材将用于建造房屋的墙壁。

Byteasar 决定房屋的地板为矩形,并且他希望使其面积尽可能大。对于大小为 $x \times y$ 的矩形地板,房屋的面积将为 $x \cdot y$。

房屋将有四面墙,每面墙都是一个矩形。对于每面墙,Byteasar 将恰好使用 $k$ 块木板,这些木板将叠放在一起。因此,他需要 $2k$ 块长度为 $x$ 的木板和 $2k$ 块长度为 $y$ 的木板。

Byteasar 可以根据自己的喜好自由地将木材切割成木板。因此,从一根长度为 $a_i$ 的木材中,他可以得到任意实数长度序列的木板 $b_1, \dots, b_m$,只要满足 $b_1 + \dots + b_m \le a_i$。Byteasar 不需要使用所有的木材,任何剩余的边角料都可以保留。

请帮助他计算他能获得的房屋的最大面积。

输入格式

输入的第一行包含两个整数 $n$ 和 $k$($1 \le n \le 1000$;$1 \le k \le 30$),分别表示木材的数量和墙壁的高度(木板层数)。

第二行包含一个由 $n$ 个整数组成的序列 $a_1, \dots, a_n$($1 \le a_i \le 1000$),表示每根木材的长度。

输出格式

输出一个实数,表示房屋的最大可能面积(即在 Byteasar 能够获得 $2k$ 块长度为 $x$ 的木板和 $2k$ 块长度为 $y$ 的木板的前提下,$x \cdot y$ 的最大值)。

允许的相对或绝对误差为 $10^{-9}$。也就是说,如果你输出的答案是 $S$,而正确的精确结果是 $R$,则必须满足 $|S - R| \le 10^{-9} \cdot \max(1, R)$。你最多可以输出小数点后 20 位数字。

样例

输入样例 1

1 5
10

输出样例 1

0.25

输入样例 2

5 1
6 7 1 3 2

输出样例 2

12

输入样例 3

5 7
1 4 5 7 5

输出样例 3

0.602

说明

在第一个样例中,我们需要 20 块木板(每面墙 5 块)。最佳方案是将唯一的一根木材切成 20 等份,每份长度为 0.5,从而建造一座面积为 $0.5 \cdot 0.5 = 0.25$ 的房屋。

在第二个样例中,我们有两种不同的方案可以获得面积为 12 的房屋:

  • 对于大小为 $6 \times 2$ 的房屋,我们需要将一根长度为 7 的木材缩短为 6,并将一根长度为 3 的木材缩短为 2。
  • 对于大小为 $4 \times 3$ 的房屋,我们需要将一根长度为 7 的木材切成长度为 3 和 4 的两块木板,并将一根长度为 6 的木材缩短为 4。

在第三个样例中,最优的房屋尺寸为 $0.7 \times 0.86$。下图展示了如何获得 14 块长度为 0.86 的木板、14 块长度为 0.7 的木板以及两块长度分别为 0.14 和 0.02 的边角料:

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1056EditorialOpen题解jiangly2026-02-19 17:49:44View

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.