Description

You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum.

Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.

You should write a program which finds sum of the best subsequence.

Input

The first line contains integer number n (1 ≤ n ≤ 105).

The second line contains n integer numbers a1, a2, ..., an ( - 104 ≤ ai≤ 104). The sequence contains at least one subsequence with odd sum.

Output

Print sum of resulting subseqeuence.

Examples
input
4
-2 2 -3 1
output
3
input
3
2 -5 -3
output
-1
Note

In the first example sum of the second and the fourth elements is 3.

题意:求子序列和最大为奇数是多少

解法:奇数和偶数相加减的关系

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath> using namespace std; const int maxn = ;
long long a[maxn],b[maxn],c[maxn],dp[maxn];
long long m,n;
long long sum;
long long Min=(1e6);
long long Minn=(1e6);
int main()
{
cin>>n;
for(int i=;i<=n;i++)
{
cin>>a[i];
if(a[i]>=)
{
sum+=a[i];
if(a[i]%)
{
Minn=min(Minn,a[i]);
}
}
else
{
long long ans=abs(a[i]);
if(ans%)
{
Min=min(ans,Min);
// cout<<Min<<endl;
}
}
}
if(sum%)
{
cout<<sum<<endl;
}
else
{
cout<<max(sum-Min,sum-Minn)<<endl;
}
return ;
}

Educational Codeforces Round 19 B的更多相关文章

  1. Educational Codeforces Round 19 A, B, C, E(xjb)

    题目链接:http://codeforces.com/contest/797 A题 题意:给出两个数n, k,问能不能将n分解成k个因子相乘的形式,不能输出-1,能则输出其因子: 思路:将n质因分解, ...

  2. Educational Codeforces Round 19

    A. k-Factorization 题目大意:给一个数n,求k个大于1的数,乘积为n.(n<=100,000,k<=20) 思路:分解质因数呗 #include<cstdio> ...

  3. Educational Codeforces Round 19 题解【ABCDE】

    A. k-Factorization 题意:给你一个n,问你这个数能否分割成k个大于1的数的乘积. 题解:因为n的取值范围很小,所以感觉dfs应该不会有很多种可能-- #include<bits ...

  4. 【Educational Codeforces Round 19】

    这场edu蛮简单的…… 连道数据结构题都没有…… A.随便质因数分解凑一下即可. #include<bits/stdc++.h> #define N 100005 using namesp ...

  5. Educational Codeforces Round 19 A+B+C+E!

    A. k-Factorization 题意:将n分解成k个大于1的数相乘的形式.如果无法分解输出-1. 思路:先打个素因子表,然后暴力判,注意最后跳出的条件. int len,a[N],b[N]; v ...

  6. Educational Codeforces Round 19 C

    Description Petya recieved a gift of a string s with length up to 105 characters for his birthday. H ...

  7. Educational Codeforces Round 19 A

    Description Given a positive integer n, find k integers (not necessary distinct) such that all these ...

  8. Educational Codeforces Round 19 E. Array Queries(暴力)(DP)

    传送门 题意 给出n个数,q个询问,每个询问有两个数p,k,询问p+k+a[p]操作几次后超过n 分析 分块处理,在k<sqrt(n)时,用dp,大于sqrt(n)用暴力 trick 代码 #i ...

  9. Educational Codeforces Round 17

    Educational Codeforces Round 17 A. k-th divisor 水题,把所有因子找出来排序然后找第\(k\)大 view code //#pragma GCC opti ...

随机推荐

  1. ln: 正在创建指向“asm-arm”的符号链接“asm”: 不支持的操作

    原因是不能在windows共享目录编译,将待编译的uboot源码copy到home目录

  2. hadoop的一般端口使用

  3. git push & git pull 推送/拉取指定分支

    https://blog.csdn.net/litianze99/article/details/52452521

  4. MAC Safari上网弹窗弹广告的最新有效解决方法

    7.3更新: 之前更改DNS好了一段时间,最近在打开其它网页时还是会弹广告: 最终解决方法: 安装MALWAREBYTES 3清理一下: 网址:Free Cyber Security & An ...

  5. JVM内存分配策略、各个代区、FullGC/MinorGC

    主要讨论默认的Serial/Serial Old内存分配: 一.几种分配方案 1.  对象优先在Eden分配: 一般情况下,对象会在新生代的Eden区分配,Eden区没有足够空间时,虚拟机会 发起一次 ...

  6. NOT IN clause and NULL values

    https://stackoverflow.com/questions/129077/not-in-clause-and-null-values This issue came up when I g ...

  7. YTU 2425: C语言习题 输出月份

    2425: C语言习题 输出月份 时间限制: 1 Sec  内存限制: 128 MB 提交: 476  解决: 287 题目描述 编写一程序,输入月份号,输出该月的英文月名.例如,输入3,则输出Mar ...

  8. hadoop源码剖析--$HADOOP_HOME/bin/hadoop脚本文件分析

    1. $HADOOP_HOME/bin/ hadoop #!/usr/bin/env bash# Licensed to the Apache Software Foundation (ASF) un ...

  9. [Selenium] 如何使用Chrome Options 定制测试Chrome 浏览器的特定属性 (类似FirefoxProfiles)

    Chrome Options 类似于FirefoxProfiles,用于定制待测试的Chrome 浏览器的特定属性 1)如果希望测试某个浏览器插件,可通过addExtensions方式提前加载以.cr ...

  10. python单元测试之unittest框架使用总结

    一.什么是单元测试 单元测试是用来对一个模块.一个函数或者一个类来进行正确性检验的测试工作. 比如对于函数abs(),我们可以编写的测试用例为: (1)输入正数,比如1.1.2.0.99,期待返回值与 ...