其他分享
首页 > 其他分享> > CodeForces - 621A Wet Shark and Odd and Even

CodeForces - 621A Wet Shark and Odd and Even

作者:互联网

题目: 传送门
思路:
保证 sum 结果为 偶数,则 a[i] 为偶数 ,一定可以加上 .
如果a[I]为奇数,我们先把其放进奇数之和里,如果最后奇数之和为偶数,直接加上,反正,减去最小的奇数即可。

#include <iostream>
#include <algorithm>
using namespace std;

long long ans = 0;
long long mins_odd=1e15,sum_odd=0;

int main() {
    int n;
    cin>>n;
    while(n--) {
        long long a;
        cin>>a;
        if(a%2==0) {
            ans+=a;
        }
        else {
            sum_odd+=a;
            mins_odd=min(mins_odd,a);
        }
    }
    cout<<ans + (sum_odd%2==0? sum_odd:sum_odd-mins_odd)<<endl;
    return 0;
}

标签:Even,Shark,621A,奇数,sum,long,偶数,mins,odd
来源: https://blog.csdn.net/qq_43305984/article/details/89184472