IBMOA #23
Find Maximum Even Sum
Estimated MediumJudge-ready
Topics (AI-labelled)GreedyBits & Math
Choose any number of items from an integer array so that their sum is even and as large as possible; choosing no items is allowed. There is at least one even element, and elements may be negative.
Input
The first line contains n, and the second line contains the array. On this site 1≤n≤200000, −10^9≤element≤10^9, and there is at least one even number.
Output
Output one integer, the answer.
Example 1
Input:
7
2 3 6 -5 10 1 1
Output:
22
Example 2
Input:
2
-2 -3
Output:
0
Example 3
Input:
3
1 1 2
Output:
4
Example notes
The examples give 22, 0 and 4 respectively; negative numbers do not have to be chosen.
Editorial
Loading solution…