Codeforces Round #341 (Div. 2)
http://codeforces.com/contest/621
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.
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.
Print the maximum possible even sum that can be obtained if we use some of the given integers.
3
1 2 3
6
5
999999999 999999999 999999999 999999999 999999999
3999999996
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.
题目很简单,判断一下奇数的个数就好了,如果奇数的个数为奇数,那么就找一个最小小的奇数去掉。还有一些细节问题
/* *********************************************** Author : Created Time :2016/2/1 9:36:28 File Name :cf341a.cpp ************************************************ */ #include <iostream> #include <cstring> #include <cstdlib> #include <stdio.h> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <iomanip> #include <list> #include <deque> #include <stack> #define ull unsigned long long #define ll long long #define mod 90001 #define INF 0x3f3f3f3f #define maxn 10000+10 #define cle(a) memset(a,0,sizeof(a)) const ull inf = 1LL << 61; const double eps=1e-5; using namespace std; bool cmp(int a,int b){ return a>b; } ll a[100010]; int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif //freopen("out.txt","w",stdout); int n; while(cin>>n){ int num=0; ll Sum=0; for(int i=1;i<=n;i++){ cin>>a[i]; if(a[i]&1)num++; Sum+=a[i]; } sort(a+1,a+1+n); if(n==1&&num==1){ cout<<0<<endl;continue; } if(num==n&&num%2==1){ cout<<Sum-a[1]<<endl; continue; } if(num%2==0){ cout<<Sum<<endl;continue; } if(num&1){ for(int i=1;i<=n;i++){ if(a[i]&1){ cout<<Sum-a[i]<<endl;break; } } continue; } } return 0; }
欢迎关注公众号: