Codeforces Round #341 (Div. 2) A. Wet Shark and Odd and Even (水)

A. Wet Shark and Odd and Even
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.

Note, that if Wet Shark uses no integers from the n integers, the sum is an even integer 0.

Input

The first line of the input contains one integer, n (1 ≤ n ≤ 100 000). The next line contains n space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.

Output

Print the maximum possible even sum that can be obtained if we use some of the given integers.

Sample test(s)
Input
3
1 2 3
Output
6
Input
5
999999999 999999999 999999999 999999999 999999999
Output
3999999996
Note

In the first sample, we can simply take all three integers for a total sum of 6.

In the second sample Wet Shark should take any four out of five integers 999 999 999.



题意:给你n个数,求其能组成的最大偶数和


思路:求总和,然后查看总和是奇数的话减去最小的那个奇数,如果是偶数就是答案


ac代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stack>
#include<set>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#define MAXN 100010
#define LL long long
#define ll __int64
#define INF 0x7fffffff
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-10
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
//head
ll num[MAXN];
int v[MAXN];
int main()
{
	int n,i,j;
	while(scanf("%d",&n)!=EOF)
	{
		ll mi=INF;
		ll ans=0;
		ll a;
		mem(v);
		for(i=0;i<n;i++)
		{
			scanf("%I64d",&a);
			if(a%2)
			mi=min(mi,a);
			ans+=a;
		}
		if(ans%2)
		{
			printf("%I64d\n",ans-mi);
		}
		else
		{
			printf("%I64d\n",ans);
		}
	}
	return 0;
}


你可能感兴趣的:(Codeforces Round #341 (Div. 2) A. Wet Shark and Odd and Even (水))