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

题意是得到最大的偶数和

解决办法很简单 排个序 取和 如果是奇数就减去最小的奇数

#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#define INF 0x3f3f3f3f
#define mem(str,x) memset(str,(x),sizeof(str))  
#define STOP puts("Pause");
using namespace std;
typedef long long LL;

LL arry[100010], ans;

int main()
{
    int n;
    scanf("%d", &n);
    ans = 0;
    for(int i = 1; i <= n; i++){
        scanf("%I64d", &arry[i]);
        ans += arry[i];
    }
    sort(arry + 1, arry + 1 + n);
    for(int i = 1; (ans & 1) && i <= n; i++){
        if(arry[i] & 1) ans -= arry[i];
    }
    printf("%I64d\n", ans);
    return 0;
}

 

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