CF797B.Odd sum

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given sequence _a_1, _a_2, ..., a__n 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.

给你一个长度为 nn 的整数序列 a1,a2,…,ana_1, a_2, \dots, a_n。你的任务是找出一个子序列,使其元素和为奇数,并且在所有和为奇数的子序列中该和最大。题目保证给定序列中至少存在一个和为奇数的子序列。

子序列是指通过删除原序列中若干元素(可以是零个),但不改变剩余元素相对顺序所得到的序列。

你需要编写一个程序,输出这个最优子序列的元素和。

输入格式

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

The second line contains n integer numbers _a_1, _a_2, ..., a__n ( - 104 ≤ a__i ≤ 104). The sequence contains at least one subsequence with odd sum.

第一行包含一个整数 $ n (( 1 \leq n \leq 10^5 $)。

第二行包含 $ n $ 个整数 $ a_1, a_2, \dots, a_n (( -10^4 \leq a_i \leq 10^4 $)。该序列中至少存在一个和为奇数的子序列。

输出格式

Print sum of resulting subseqeuence.

输出所得子序列的和。

输入输出样例

  • 输入#1

    4
    -2 2 -3 1

    输出#1

    3
  • 输入#2

    3
    2 -5 -3

    输出#2

    -1

说明/提示

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

在第一个例子中,第二个和第四个元素的和为 3。

输入解题思路,AI测评打分。不知道怎么写?

首页