codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

797B.md (1148B)


      1 Source: https://codeforces.com/problemset/problem/797/B
      2 
      3 B. Odd sum
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
     24 
     25 You should write a program which finds sum of the best subsequence.
     26 
     27 Input
     28 
     29 The first line contains integer number *n* (1 ≤ *n* ≤ 105).
     30 
     31 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.
     32 
     33 Output
     34 
     35 Print sum of resulting subseqeuence.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 4  
     43 -2 2 -3 1
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 3
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 3  
     56 2 -5 -3
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 -1
     63 ```
     64 
     65 Note
     66 
     67 In the first example sum of the second and the fourth elements is 3.