CodeForces 621A Wet Shark and Odd and Even

水题

#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<vector>
#include<algorithm>
using namespace std;

int n;
long long a[100000+10];

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%lld",&a[i]);
    sort(a,a+n);

    long long ans1=0,ans2=0,num=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]%2==0) ans1=ans1+a[i];
        else ans2=ans2+a[i],num++;
    }
    if(num%2==0) printf("%lld\n",ans1+ans2);
    else
    {
        for(int i=0;i<n;i++)
            if(a[i]%2==1)
                {ans2=ans2-a[i];break;}
        printf("%lld\n",ans1+ans2);
    }
    return 0;
}

 

你可能感兴趣的:(CodeForces 621A Wet Shark and Odd and Even)