797B. Odd sum
B. Odd sum:题目
一道小小的贪心
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> a((int)6e5);
vector<int> b((int)6e5), c[(int)6e5];
const int mod = 1e9 + 7;
string s;
multiset<int> se;
signed main()
{int n;cin >> n;int res = -0x3f3f3f3f;for (int i = 0; i < n; i++){cin>>a[i];if (a[i]&1) res = max(res,a[i]);}sort(a.begin(),a.begin()+n);int sum = 0,cou = 0x3f3f3f3f;for (int i=n-1;i>=0;i--){if (a[i]>0) sum+=a[i];if (a[i]&1){if (abs(a[i])<abs(cou)) cou = abs(a[i]);}}if (sum&1) res = sum;else res = max(res,sum-cou);cout<<res<<endl;
}
797B. Odd sum相关推荐
- Codeforces 797B - Odd sum
B. Odd sum 题目链接:http://codeforces.com/problemset/problem/797/B time limit per test 1 second memory l ...
- Array with Odd Sum CodeForces - 1296A
You are given an array aa consisting of nn integers. In one move, you can choose two indices 1≤i,j≤n ...
- Array with Odd Sum(CF-1296A)
Problem Description You are given an array a consisting of n integers. In one move, you can choose t ...
- Odd Sum Segments(CF-1196B)
Problem Description You are given an array aa consisting of nn integers a1,a2,-,an. You want to spli ...
- Codeforces 1196B Odd Sum Segments
https://codeforces.com/contest/1196/problem/B 题解:贪心 /* *@Author: STZG *@Language: C++ */ #include &l ...
- Codeforces 题目合集+分类+代码 【Updating...】【361 in total】
961A - Tetris 模拟 ...
- 语言趣味编程100例无水印_趣味c语言编程100例(三)
经典c程序100例==51--60 [程序51] 题目:学习使用按位与 & . 1.程序分析:0&0=0; 0&1=0; 1&0=0; 1&1=1 2.程序源代 ...
- C语言练习题100道
最近有人给我要联系C语言的一些例题,从网上找了一写,顺便写到这里 [程序1] 题目:有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 1.程序分析:可填在百位.十位.个位的 ...
- HEOI2012 朋友圈
这是做的最得意的一道题,当时在考场上得了90,是因为数据中A有100++的情况,Runtime_error了.. 首先强调,本人不是用二分图,或者说不用图论算法,只涉及简单的枚举和记忆化思想. A国的 ...
最新文章
- 大数据和数据库的理解文章收藏
- AI伪装目标检测:让变色龙现出原形!
- Linux学习笔记(一)|目录结构
- nba2k19登陆显示你与服务器,NBA2K19无法登陆了?NBA2K19连不上服务器怎么办?[图]...
- 在dom最前面插入_前端性能优化之dom编程
- java常用的网关有哪几种_拼多多java开发一面、二面合并面经
- 使用windows 10 安装中文版语言
- ACM 学习笔记(一) 常用STL讲解
- 自己实现LinkedList类
- Windows Server 2016 身份管理 (MCSA 认证 70-742)-李海园-专题视频课程
- excel文件修复工具_免费的PDF转Word软件有哪些?各种文件格式转换工具推荐
- 工程测量内业中提取横断面线折点坐标数据并写入文件
- 令人忧虑,不阅读的中国人
- [译] 如果界面产品设计师设计实体产品
- R、RStudio下载与安装方法
- 三、路由协议——直连路由、静态路由、缺省路由、路由优先级和路由度量、路由冗余和备份(浮动静态路由)
- 破解并修复VoLTE:利用隐藏的数据通道和错误的实现方式
- java自动转换与强制转换
- SpringBoot 三大开发工具,你都用过么?
- 生育 生殖 長壽의 三情은 萬物의 本能 (韓長庚 易學原理總論)
热门文章
- MyEclipse2015修改项目部署名称(WebContextRoot)
- PHP API接口GETPOST请求封装(通用)
- Android.View.InflateException: Binary XML File Line #异常的解决
- 计算机网络西北大学,西北大学计算机网络复习资料 (拟).doc
- jquery ajax post请求连续多个问号特殊数据异常问题
- lambda写法(多参数)
- json 微信小程序 筛选_微信小程序学习记录
- mybatis plus 新增,修改
- vue-router 路由跳转
- 电子计算机职专东校区在哪,自贡计算机电子信息职业技术学校位置在哪儿