CF1223G.Wooden Raft
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Suppose you are stuck on a desert island. The only way to save yourself is to craft a wooden raft and go to the sea. Fortunately, you have a hand-made saw and a forest nearby. Moreover, you've already cut several trees and prepared it to the point that now you have n logs and the i-th log has length ai.
The wooden raft you'd like to build has the following structure: 2 logs of length x and x logs of length y. Such raft would have the area equal to x⋅y. Both x and y must be integers since it's the only way you can measure the lengths while being on a desert island. And both x and y must be at least 2 since the raft that is one log wide is unstable.
You can cut logs in pieces but you can't merge two logs in one. What is the maximum area of the raft you can craft?
假设你被困在一座荒岛上。唯一能自救的方法是制作一个木筏,然后出海求生。幸运的是,你有一把手工制作的锯子,附近还有一片森林。此外,你已经砍伐了若干棵树,并完成了前期准备工作,现在你手头有 n 根原木,其中第 i 根原木的长度为 ai。
你希望制作的木筏结构如下:需要 2 根长度为 x 的原木,以及 x 根长度为 y 的原木。这样的木筏面积为 x⋅y。由于在荒岛上只能进行整数长度的测量,因此 x 和 y 都必须是正整数;并且 x 和 y 均至少为 2,因为仅由一根原木构成宽度的木筏是不稳定的。
你可以将原木锯成更短的段,但不能将两根原木拼接成一根。请问:你能制作的木筏的最大面积是多少?
输入格式
The first line contains the only integer n (1≤n≤5⋅105) — the number of logs you have.
The second line contains n integers a1,a2,…,an (2≤ai≤5⋅105) — the corresponding lengths of the logs.
It's guaranteed that you can always craft at least 2×2 raft.
第一行包含唯一一个整数 n(1≤n≤5⋅105)—— 表示你拥有的原木数量。
第二行包含 n 个整数 a1,a2,…,an(2≤ai≤5⋅105)—— 分别表示各根原木的长度。
保证你总能制作出至少一个 2×2 的木筏。
输出格式
Print the only integer — the maximum area of the raft you can craft.
输出唯一的整数——你能制作的木筏的最大面积。
输入输出样例
输入#1
1 9
输出#1
4
输入#2
9 9 10 9 18 9 9 9 28 9
输出#2
90
说明/提示
In the first example, you can cut the log of the length 9 in 5 parts: 2+2+2+2+1. Now you can build 2×2 raft using 2 logs of length x=2 and x=2 logs of length y=2.
In the second example, you can cut a4=18 into two pieces 9+9 and a8=28 in three pieces 10+9+9. Now you can make 10×9 raft using 2 logs of length 10 and 10 logs of length 9.
在第一个例子中,你可以将长度为 9 的原木切成 5 段:2+2+2+2+1。现在你可以用 2 根长度为 x=2 的原木和 2 根长度为 y=2 的原木搭建一个 2×2 的木筏。
在第二个例子中,你可以将 a4=18 切成两段:9+9,并将 a8=28 切成三段:10+9+9。现在你可以用 2 根长度为 10 的原木和 10 根长度为 9 的原木搭建一个 10×9 的木筏。
输入解题思路,AI测评打分。不知道怎么写?