Code Forces 525C Ilya and Sticks

E - E
Time Limit:2000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u

Description

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 li.

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 a1, a2, a3 and a4 can make a rectangle if the following properties are observed:

  • a1 ≤ a2 ≤ a3 ≤ a4
  • a1 = a2
  • a3 = a4

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?

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 105) — the number of the available sticks.

The second line of the input contains n positive integers li (2 ≤ li ≤ 106) — the lengths of the sticks.

Output

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.

Sample Input

Input
4
2 4 4 2
Output
8
Input
4
2 2 3 5
Output
0
Input
4
100003 100004 100005 100006
Output
10000800015

给定一些木棒的长度,问这些木棒能构成的矩形最大面积和是多少。

思路是就贪心。排序后从大到小。

注意要用 long long.

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
long long a[100005];
long long s[100005];
int main()
{
    int n;
    scanf("%d",&n);
    memset(s,0,sizeof(s));
    for(int i=0;i<n;i++)
        scanf("%I64d",&a[i]);
    sort(a,a+n);
    int i=n-1;
    int edge=-1;
    while(i>0)
    {
        if(a[i]==a[i-1]||a[i]==(a[i-1]+1))
        {
            if(edge==-1)
                edge=a[i-1];
            else
            {
                s[i-1]=edge*a[i-1];
                edge=-1;
            }
            i-=2;
        }
        else
        {
            i--;
        }
    }
    long long sum=0;
    for(int i=0;i<100005;i++)
    {
        if(s[i]!=0)
            sum+=s[i];
    }
    printf("%I64d\n",sum);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值