#GD0000180. Tổng lẻ lớn nhất (Odd Sum)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tổng lẻ lớn nhất (Odd Sum)
Odd Sum
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given integers , possibly positive or negative. You may choose a subsequence, obtained by deleting some elements while preserving the order of those retained. The sum of the chosen numbers must be odd. It is guaranteed that at least one valid subsequence exists. Find the maximum possible odd sum.
Input
Line 1 contains the integer , the sequence length.
Line 2 contains exactly integers in their original order. At least one element is odd.
Output
Print one integer: the largest odd sum of a valid subsequence.
Subtasks
- Subtask 1 (20 points): ; for every ; at least one is odd.
- Subtask 2 (30 points): ; for every ; at least one is odd.
- Subtask 3 (50 points): ; for every ; at least one is odd.
Examples
Example 1
Input
4
-2 2 -3 1
Output
3
Explanation
The sequence is . Selecting and gives the odd sum . All other elements are negative, so including them cannot improve this sum. The sum of all positive elements is already .
Example 2
Input
3
2 -5 -3
Output
-1
Explanation
The only positive element contributes , which is even. Adding gives , whereas adding gives . The former is the larger odd sum, and no other choice can improve it.