A9802 | Ilya and Sticks
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of $n$ sticks and an instrument. Each stick is characterized by its length $l_{i}$ .
Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maximizes their total area. Each stick is used in making at most one rectangle, it is possible that some of sticks remain unused. Bending sticks is not allowed.
Sticks with lengths $a_{1}$ , $a_{2}$ , $a_{3}$ and $a_{4}$ can make a rectangle if the following properties are observed:
- $a_{1}<=a_{2}<=a_{3}<=a_{4}$
- $a_{1}=a_{2}$
- $a_{3}=a_{4}$
A rectangle can be made of sticks with lengths of, for example, $3 3 3 3$ or $2 2 4 4$ . A rectangle cannot be made of, for example, sticks $5 5 5 7$ .
Ilya also has an instrument which can reduce the length of the sticks. The sticks are made of a special material, so the length of each stick can be reduced by at most one. For example, a stick with length $5$ can either stay at this length or be transformed into a stick of length $4$ .
You have to answer the question — what maximum total area of the rectangles can Ilya get with a file if makes rectangles from the available sticks?
Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maximizes their total area. Each stick is used in making at most one rectangle, it is possible that some of sticks remain unused. Bending sticks is not allowed.
Sticks with lengths $a_{1}$ , $a_{2}$ , $a_{3}$ and $a_{4}$ can make a rectangle if the following properties are observed:
- $a_{1}<=a_{2}<=a_{3}<=a_{4}$
- $a_{1}=a_{2}$
- $a_{3}=a_{4}$
A rectangle can be made of sticks with lengths of, for example, $3 3 3 3$ or $2 2 4 4$ . A rectangle cannot be made of, for example, sticks $5 5 5 7$ .
Ilya also has an instrument which can reduce the length of the sticks. The sticks are made of a special material, so the length of each stick can be reduced by at most one. For example, a stick with length $5$ can either stay at this length or be transformed into a stick of length $4$ .
You have to answer the question — what maximum total area of the rectangles can Ilya get with a file if makes rectangles from the available sticks?
输入格式
The first line of the input contains a positive integer $n$ ( $1<=n<=10^{5}$ ) — the number of the available sticks.
The second line of the input contains $n$ positive integers $l_{i}$ ( $2<=l_{i}<=10^{6}$ ) — the lengths of the sticks.
The second line of the input contains $n$ positive integers $l_{i}$ ( $2<=l_{i}<=10^{6}$ ) — the lengths of the sticks.
输出格式
The first line of the output must contain a single non-negative integer — the maximum total area of the rectangles that Ilya can make from the available sticks.
输入输出样例
输入 #1
4 2 4 4 2
输出 #1
8
输入 #2
4 2 2 3 5
输出 #2
0
输入 #3
4 100003 100004 100005 100006
输出 #3
10000800015
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted