Codeforces 621A Wet Shark and Odd and Even 【水题】

来源:互联网 发布:家道中落 知乎 编辑:程序博客网 时间:2024/05/22 12:46

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
31 2 3
output
6
input
5999999999 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个数中找出最大的偶数和sum。


AC代码:

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <set>#include <vector>#include <string>#define INF 1000000#define eps 1e-8#define MAXN (100000+10)#define MAXM (100000+10)#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rf(a) scanf("%lf", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%.2lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while((a)--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 1000000007#define LL long long#define lson o<<1, l, mid#define rson o<<1|1, mid+1, r#define ll o<<1#define rr o<<1|1#define PI acos(-1.0)#pragma comment(linker, "/STACK:102400000,102400000")#define fi first#define se secondusing namespace std;typedef pair<int, int> pii;LL a[MAXN];int main(){    int n, m; Ri(n);    for(int i = 1; i <= n; i++) Rl(a[i]);    sort(a+1, a+n+1);    LL sum1 = 0, sum2 = 0;    int num = 0;    for(int i = n; i >= 1; i--)    {        if(a[i] & 1)        {            sum2 += a[i];            num++;        }        else            sum1 += a[i];    }    LL sum = sum1 + sum2; LL temp;    if(num & 1)    {        for(int i = 1; i <= n; i++)        {            if(a[i] & 1)            {                temp = a[i];                break;            }        }        sum -= temp;    }    Pl(sum);    return 0;}



0 0
原创粉丝点击