Codeforces 621A Wet Shark and Odd and Even 【水题】
来源:互联网 发布:家道中落 知乎 编辑:程序博客网 时间:2024/05/22 12:46
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个数中找出最大的偶数和sum。
AC代码:
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <set>#include <vector>#include <string>#define INF 1000000#define eps 1e-8#define MAXN (100000+10)#define MAXM (100000+10)#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rf(a) scanf("%lf", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%.2lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while((a)--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 1000000007#define LL long long#define lson o<<1, l, mid#define rson o<<1|1, mid+1, r#define ll o<<1#define rr o<<1|1#define PI acos(-1.0)#pragma comment(linker, "/STACK:102400000,102400000")#define fi first#define se secondusing namespace std;typedef pair<int, int> pii;LL a[MAXN];int main(){ int n, m; Ri(n); for(int i = 1; i <= n; i++) Rl(a[i]); sort(a+1, a+n+1); LL sum1 = 0, sum2 = 0; int num = 0; for(int i = n; i >= 1; i--) { if(a[i] & 1) { sum2 += a[i]; num++; } else sum1 += a[i]; } LL sum = sum1 + sum2; LL temp; if(num & 1) { for(int i = 1; i <= n; i++) { if(a[i] & 1) { temp = a[i]; break; } } sum -= temp; } Pl(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
- WebService流行框架之Axis和CXF
- 10.Swift 中的闭包
- 双目立体视觉系统精度分析
- springMVC详细配置+Mysql+jdbcTemplate实现分页功能
- 设计模式:装饰模式
- Codeforces 621A Wet Shark and Odd and Even 【水题】
- 树莓派DIY网站,极客范
- 实战:用BEAST构建带分子钟的皿蛛分子系统发育树
- 推荐一个不错的bootstrap学习网站
- webview常用方法
- Android中的SharedPreferences陷阱 [转]
- 用红外遥控器遥控树莓派(XBMC)
- 调试opencv程序显示应用程序无法正常启动,0xc000007b
- 同态滤波及图像去阴影