2016.13周 周练A - Wet Shark and Odd and Even【CF】

来源:互联网 发布:设计师素材网站知乎 编辑:程序博客网 时间:2024/06/03 12:26
A - Wet Shark and Odd and Even
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

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 Input

Input
31 2 3
Output
6
Input
5999999999 999999999 999999999 999999999 999999999
Output
3999999996

Hint

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.


题意:给一组数,含偶数和奇数,问相加的偶数和最大为多少。

解:

当奇数有2N+1个时,所有数的和减去最小的奇数;

当奇数有2N个时,就求所有数的和。

#include <cstdio>#include <algorithm>using namespace std;int main() {int n;long long a[100010],s1,s2,m,ans;while(~scanf("%d",&n)){s1=0;ans=0;for(int i=0;i<n;i++){scanf("%lld",&a[i]);s1+=a[i];if(a[i]%2==1)ans++;} sort(a,a+n);m=0;if(ans%2==1){for(int i=0;i<n;i++){if(a[i]%2==1){m=a[i];break;}}}s2=s1-m;printf("%lld\n",s2);}return 0;}


0 0
原创粉丝点击