CodeForces 525C Ilya and Sticks 贪心
题目:click here
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long ll;
using namespace std;
const int M = 1e5+5;
int n;
int a[M];
int b[M];
bool cmp( int a, int b ) { //从大到小排序
return a > b;
}
int main()
{
while( ~scanf("%d", &n ) ) {
memset( b, 0, sizeof(b) );
for( int i=0; i<n; i++ )
scanf("%d", a+i);
sort( a, a+n, cmp );
int cnt = 0;
for( int i=0; i<n-1; i++ ) {
if( a[i]-a[i+1] <= 1 ) {
b[cnt++] = a[i+1];
i++;
}
}
ll sum = 0;
for( int i=0; i<cnt-cnt%2; i+=2 ) {
sum += (ll)b[i]*(ll)b[i+1];
}
printf("%I64d\n", sum );
}
return 0;
}