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

来源:互联网 发布:数据库架构师职责 编辑:程序博客网 时间:2024/05/22 12:01
A. Wet Shark and Odd and Even
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 by2) 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 integer0.

Input

The first line of the input contains one integer, n (1 ≤ n ≤ 100 000). The next line containsn space separated integers given to Wet Shark. Each of these integers is in range from1 to 109, inclusive.

Output

Print the maximum possible even sum that can be obtained if we use some of the given integers.

Sample test(s)
Input
31 2 3
Output
6
Input
5999999999 999999999 999999999 999999999 999999999
Output
3999999996
Note

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个数,求其能组成的最大偶数和


思路:求总和,然后查看总和是奇数的话减去最小的那个奇数,如果是偶数就是答案


ac代码:

#include<stdio.h>#include<math.h>#include<string.h>#include<stack>#include<set>#include<queue>#include<vector>#include<iostream>#include<algorithm>#define MAXN 100010#define LL long long#define ll __int64#define INF 0x7fffffff#define mem(x) memset(x,0,sizeof(x))#define PI acos(-1)#define eps 1e-10using namespace std;int gcd(int a,int b){return b?gcd(b,a%b):a;}LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}//headll num[MAXN];int v[MAXN];int main(){int n,i,j;while(scanf("%d",&n)!=EOF){ll mi=INF;ll ans=0;ll a;mem(v);for(i=0;i<n;i++){scanf("%I64d",&a);if(a%2)mi=min(mi,a);ans+=a;}if(ans%2){printf("%I64d\n",ans-mi);}else{printf("%I64d\n",ans);}}return 0;}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 赴日签证申请表写错了怎么办 不知道自己想要做什么工作怎么办 三星note4微信出现闪退怎么办 魅蓝note6手机自动闪退怎么办 苹果6s系统内存占用量过大怎么办 想在一年通过会计初级和中级怎么办 特殊岗位退休档察写的力工怎么办 面试时期望工资说低了。怎么办 面试时期望薪资写低了怎么办 高考后比一模差了80分怎么办 戒了烟我不习惯没有你我怎么办 没有你我不习惯没有你我怎么办 做什么都没兴趣嫌麻烦怎么办 快递还在路上就确认收货了怎么办 微信显示时间与手机不符怎么办 微信提示银行卡预留手机不符怎么办 得了湿疹后吃了海鲜严重了怎么办 看到小区街道乱扔的垃圾你会怎么办 去韩国干服务员不会讲韩语怎么办 华为手机键盘变英文字母大了怎么办 淘宝申请售后卖家余额不足怎么办 发票名称少写了一个字怎么办 微博数量与实际数量不一致怎么办 在淘宝中要买的商品卖完了怎么办 病因写错了保险不报销怎么办? 上学期间保险名字写错了怎么办 塑料盆上的商标纸撕了胶怎么办 川航买机票名字错了两个字怎么办 买机票护照号码填错了怎么办 换旅行证给孩子改名字怎么办 浦发信用卡卡片名字印错了怎么办 公主工作很辛苦坚持不下去怎么办 在表格里怎么办名字转换成拼音 激素脸有黑头毛孔大该怎么办 兢兢业业上班但不招领导喜欢怎么办 身体长的还算苗条但就屁股大怎么办 我想学英语从基础开始要怎么办 政府单位领导给我调岗我该怎么办 领导在单位想捞钱我该怎么办 单位领导是宵小之人我该怎么办 一件事想不明白非得想明白怎么办