远端评测题 1000ms 256MiB

Odd sum

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Odd sum

题面翻译

题目描述:

现给予你一个长度为n,包含正整数的序列 a1,a2……an,你的任务是找到一个和为奇数且值最大(在和为奇数的子序列中)的子序列。可以保证该序列中有和为奇数的子序列 子序列是一个可以通过删除一个序列中的部分元素,但不改变其他元素的顺序后得到的新序列 现在请你写一个程序找到上述的这样一个子序列

输入格式:

第一行包含一个整数***(1<=n<=10^5)*** 第二行包含n个整数a1,a2……an(-10^4<=ai<=10^4) 该序列包含至少一个和为奇数的子序列

输出格式:

输出找到的子序列的和

说明:

第一个样例中的第二个元素与第四个元素的和为3

题目描述

You are given sequence a1,a2,...,an a_{1},a_{2},...,a_{n} of integer numbers of length n 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.

输入格式

The first line contains integer number n n ( 1<=n<=105 1<=n<=10^{5} ).

The second line contains n n integer numbers a1,a2,...,an a_{1},a_{2},...,a_{n} ( 104<=ai<=104 -10^{4}<=a_{i}<=10^{4} ). The sequence contains at least one subsequence with odd sum.

输出格式

Print sum of resulting subseqeuence.

样例 #1

样例输入 #1

4
-2 2 -3 1

样例输出 #1

3

样例 #2

样例输入 #2

3
2 -5 -3

样例输出 #2

-1

提示

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

12.31下午3点50练习及作业

未认领
状态
已结束
题目
5
开始时间
2023-12-31 16:00
截止时间
2024-1-31 23:59
可延期
24 小时