B. Odd sum

Codeforces
IDCF797B
Time1000ms
Memory256MB
Difficulty
dpgreedyimplementation
English · Original
Chinese · Translation
Formal · Original
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. ## Input 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. ## Output Print sum of resulting subseqeuence. [samples] ## Note In the first example sum of the second and the fourth elements is 3.
给定一个长度为 #cf_span[n] 的整数序列 #cf_span[a1, a2, ..., an]。你的任务是找到一个子序列,使得其交错和为奇数,并且在所有满足此条件的子序列中最大。题目保证给定序列中至少存在一个交错和为奇数的子序列。 子序列是指通过删除原序列中的一些元素(不改变剩余元素的顺序)而得到的序列。 你需要编写一个程序,找出最优子序列的和。 第一行包含整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 105])。 第二行包含 #cf_span[n] 个整数 #cf_span[a1, a2, ..., an] (#cf_span[ - 104 ≤ ai ≤ 104])。序列中至少包含一个交错和为奇数的子序列。 请输出所求子序列的和。 在第一个例子中,第二个和第四个元素的和为 #cf_span[3]。 ## Input 第一行包含整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 105])。第二行包含 #cf_span[n] 个整数 #cf_span[a1, a2, ..., an] (#cf_span[ - 104 ≤ ai ≤ 104])。序列中至少包含一个交错和为奇数的子序列。 ## Output 请输出所求子序列的和。 [samples] ## Note 在第一个例子中,第二个和第四个元素的和为 #cf_span[3]。
**Definitions** Let $ n \in \mathbb{Z}^+ $ denote the length of the sequence. Let $ A = (a_1, a_2, \dots, a_n) $ be a sequence of integers, where $ a_i \in \mathbb{Z} $ and $ -10^4 \leq a_i \leq 10^4 $. **Constraints** 1. $ 1 \leq n \leq 10^5 $ 2. The sequence $ A $ contains at least one subsequence with odd sum. **Objective** Find the maximum sum $ S $ among all subsequences of $ A $ such that $ S $ is odd: $$ S = \max \left\{ \sum_{i \in I} a_i \,\middle|\, I \subseteq \{1, 2, \dots, n\},\ \sum_{i \in I} a_i \text{ is odd} \right\} $$
Samples
Input #1
4
-2 2 -3 1
Output #1
3
Input #2
3
2 -5 -3
Output #2
\-1
API Response (JSON)
{
  "problem": {
    "name": "B. Odd sum",
    "description": {
      "content": "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",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF797B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "给定一个长度为 #cf_span[n] 的整数序列 #cf_span[a1, a2, ..., an]。你的任务是找到一个子序列,使得其交错和为奇数,并且在所有满足此条件的子序列中最大。题目保证给定序列中至少存在一个交错和为奇数的子序列。\n\n子序列是指通过删除原序列中的一些元素(不改变剩余元素的顺序)而得到的序列。\n\n你需要编写一个程序,找出最优子序列的和。\n\n第一行包含整数 #cf_span[n...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ denote the length of the sequence.  \nLet $ A = (a_1, a_2, \\dots, a_n) $ be a sequence of integers, where $ a_i \\in \\mathbb{Z} $ and $ -10^4 \\leq a_i \\leq 1...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments