1849.Odd sum

Time Limit: 1s Memory Limit: 256MB

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 Format(From the terminal/stdin)

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

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

Output Format(To the terminal/stdout)

Print sum of resulting subseqeuence.

Sample Input 1

Copy
4
-2 2 -3 1
 \n
  · ·  · \n

Sample Output 1

Copy
3
 \n

Sample Input 2

Copy
3
2 -5 -3
 \n
 ·  ·  \n

Sample Output 2

Copy
-1
  \n

Hints

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

Submit

请先 登录

© 2025 FAQs