Codeforces 621A Wet Shark and Odd and Even
来源:互联网 发布:淘宝网智能手机 编辑:程序博客网 时间:2024/05/22 12:17
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.
31 2 3
6
5999999999 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.
题意:给出n个数,求取任意个数相加的和且是偶数,最大是多少?
题解:把n个数相加得sum,统计奇数的个数,个数为奇数,sum减去最小的奇数就好了。
代码如下:
#include<cstdio>#define LL __int64#define INF 1111111111LL a;int main(){int n,i,j,cnt;LL min,sum;while(scanf("%d",&n)!=EOF){sum=0; cnt=0;min=INF;for(i=0;i<n;++i){scanf("%I64d",&a);if(a&1){cnt++;if(a<min)min=a;}sum+=a;}if(cnt>0&&cnt&1)printf("%I64d\n",sum-min);elseprintf("%I64d\n",sum);}return 0;}
- Codeforces 621A Wet Shark and Odd and Even
- Codeforces 621A Wet Shark and Odd and Even 【水题】
- Codeforces 621A Wet Shark and Odd and Even
- CodeForces 621A-Wet Shark and Odd and Even
- CodeForces 621 A Wet Shark and Odd and Even
- 【CodeForces】[621A]Wet Shark and Odd and Even
- codeforces 621A Wet Shark and Odd and Even
- CodeForces A. Wet Shark and Odd and Even
- A. Wet Shark and Odd and Even
- CF 621A Wet Shark and Odd and Even
- CodeForces--621A--Wet Shark and Odd and Even(数学水题)
- CodeForces 621 A. Wet Shark and Odd and Even(水~)
- 【CodeForces】#621A - Wet Shark and Odd and Even(水)
- Codeforces Round #341 (Div. 2) --A. Wet Shark and Odd and Even
- Codeforces Round #341 (Div. 2)-A. Wet Shark and Odd and Even(奇数+奇数为偶数)
- Codeforces Round #341 (Div. 2) A. Wet Shark and Odd and Even (水)
- Codeforces Round #341 (Div. 2)A Wet Shark and Odd and Even
- CF621A - Wet Shark and Odd and Even
- 重建二叉树
- iOS UIProgressView控件用法
- iOS开发篇——UITextField
- 哈希表字符串匹配
- UISlider用法总结
- Codeforces 621A Wet Shark and Odd and Even
- 刚试了一下,浏览器里可以玩 Windows 95
- 重设(Resize)Bitmap大小以及获取到圆形头像(Rounded Avatar)的方法
- A*启发式搜索算法详解 人工智能
- 补充:函数间只能用this
- [android]_[ImageView点击变暗]
- Codeforces Round #341 (Div. 2) C. Wet Shark and Flowers
- resultType跟resultMap不能同时存在
- Codeforces 621B Wet Shark and Bishops(判定对角线点+组合数统计)