Codeforces Round #341 (Div. 2)A
2 seconds
256 megabytes
standard input
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 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.
题意: n个数字 求任意组合求和后为2的倍数的最大值
题解:n个数求和 sum 同时找到最小的为奇数的值(排序处理)sum为偶数 直接输出 若为奇数 减去最小奇数 输出
#include<bits/stdc++.h>
#define LL __int64
using namespace std;
int n;
LL a[100005];
LL sum=0;
int main()
{
scanf("%d",&n);
sum=0;
for(int i=0;i<n;i++)
{
scanf("%I64d",&a[i]);
sum+=a[i];
}
sort(a,a+n);
for(int j=0;j<n;j++)
{
if(sum%2==0)
break;
if(a[j]%2==1)
{
sum=sum-a[j];
break;
}
}
printf("%I64d\n",sum);
return 0;
}
Codeforces Round #341 (Div. 2)A的更多相关文章
- Codeforces Round #341 (Div. 2) E. Wet Shark and Blocks dp+矩阵加速
题目链接: http://codeforces.com/problemset/problem/621/E E. Wet Shark and Blocks time limit per test2 se ...
- Codeforces Round #341 (Div. 2) D. Rat Kwesh and Cheese 数学
D. Rat Kwesh and Cheese 题目连接: http://www.codeforces.com/contest/621/problem/D Description Wet Shark ...
- Codeforces Round #341 Div.2 D. Rat Kwesh and Cheese
嗯本来想着直接算出来不就行了吗 然后我想到了200^200^200....... 好吧其实也不难取两次log就行了 然后我第一次写出来log就写残了........... log里面的拆分要仔细啊.. ...
- Codeforces Round #341 Div.2 C. Wet Shark and Flowers
题意: 不概括了..太长了.. 额第一次做这种问题 算是概率dp吗? 保存前缀项中第一个和最后一个的概率 然后每添加新的一项 就解除前缀和第一项和最后一项的关系 并添加新的一项和保存的两项的关系 这里 ...
- Codeforces Round #341 Div.2 B. Wet Shark and Bishops
题意:处在同一对角线上的主教(是这么翻译没错吧= =)会相互攻击 求互相攻击对数 由于有正负对角线 因此用两个数组分别保存每个主教写的 x-y 和 x+y 然后每个数组中扫描重复数字k ans加上kC ...
- Codeforces Round #341 (Div. 2)
在家都变的懒惰了,好久没写题解了,补补CF 模拟 A - Wet Shark and Odd and Even #include <bits/stdc++.h> typedef long ...
- Codeforces Round #341 Div.2 A. Wet Shark and Odd and Even
题意是得到最大的偶数和 解决办法很简单 排个序 取和 如果是奇数就减去最小的奇数 #include <cstdio> #include <cmath> #include < ...
- Codeforces Round #341 (Div. 2) ABCDE
http://www.cnblogs.com/wenruo/p/5176375.html A. Wet Shark and Odd and Even 题意:输入n个数,选择其中任意个数,使和最大且为奇 ...
- Codeforces Round #341 (Div. 2) E - Wet Shark and Blocks
题目大意:有m (m<=1e9) 个相同的块,每个块里边有n个数,每个数的范围是1-9,从每个块里边取出来一个数组成一个数,让你求组成的方案中 被x取模后,值为k的方案数.(1<=k< ...
- Codeforces Round #341 (Div. 2) C. Mike and Chocolate Thieves 二分
C. Mike and Chocolate Thieves time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
随机推荐
- JS的六大对象:Global、Math、Number、Date、JSON、console,运行在服务器上方的支持情况分析
在ASP中使用runat="server"来调用JS的相关函数,代码如下: <script runat="server" language="j ...
- beego 笔记
1.开发文档 https://beego.me/docs/intro/ 2.bee run projectname demo controller package autoscaler import ...
- 从零开始的Python学习Episode 1
一.输入与输出 1.输入 input("number:") num = input("number:") 下面一段可以把输入的信息存在num中. 注意:输入的信 ...
- 六: Image Viewer 离线镜像查看器
参考:http://hadoop.apache.org/docs/r2.6.3/hadoop-project-dist/hadoop-hdfs/HdfsImageViewer.html 离线镜像查 ...
- Python3 循环表达式
一 While循环 基本循环 while 条件: 执行内容 #循环体 ... #循环体 ... #循环体 # 若条件为真,执行循环体内容 # 若条件为假,不执行循环体内容 实例1(Python 3.0 ...
- 软件工程 part4 评价3作品 修改
作品1 抢答器 地址: https://modao.cc/app/ylGTXobcMU7ePNi6tY53gG4iraLl0md评价: 老师有意见,我重新评价,这个作品是我测试最方便的,地址点进去直接 ...
- 软件工程 作业part1 自我介绍
自我介绍 老师您好,我叫宋雨,本科在长春理工大学,专业是计算机科学与技术. 1.回想一下你曾经对计算机专业的畅想:当初你是如何做出选择计算机专业的决定?你认为过去接触的课程是否符合你对计算机专业的期待 ...
- oracle数据库之游标的使用
一.游标概念 为了处理 SQL 语句,ORACLE 必须分配一片叫上下文( context area )的区域来处理所必需的信息,其中包括要处理的行的数目,一个指向语句被分析以后的表示形式的指针以及查 ...
- python学习笔记02:运行python程序
1.启动cmd命令行,输入python后回车,运行python解释器: 输入python代码后回车: print('Hello World')
- CSS 经典三列布局
一 圣杯布局 1 html结构 <!DOCTYPE html> <html> <head> <title></title> <link ...