## UCC Coding Competition '21 P2 - Emerald Exchange

View as PDF

Points: 3 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

You are walking along the street when a street vendor offers you a special deal. He has a row of emeralds with different sizes. Each emerald has an integer weight between and , inclusive, and the weights are clearly labelled for each emerald. However, the vendor tells you that you should not touch or buy the emeralds with odd-numbered weights as they have dangerous magical properties.

The vendor offers you to buy any number of consecutive emeralds from his row, as long as that selection of emeralds does not include any odd-weighted emeralds.

What is the largest total weight of emeralds you can buy with one purchase, following the rule above?

#### Input Specification

The input will consist of two lines. The first line contains , the number of emeralds in the vendor's row. The second line contains space-separated integers between and inclusive, the weight of each emerald in the order that the vendor has them on display.

#### Output Specification

Please output one integer: the maximum possible sum of the weights of the emeralds that can be purchased as described above.

#### Constraints and Partial Marks

For of the available marks, .

For the remaining marks, .

#### Sample Input

13
2 3 4 4 5 6 1 2 2 2 1 8 2

#### Sample Output

10

#### Explanation of Sample Output

Buying the two rightmost emeralds, with sizes and (sum = ), is the optimal purchase.

There are many suboptimal alternative purchases. These include:

• Buying the three consecutive emeralds with size (sum = ),
• Buying two of the three consecutive emeralds with size (sum = ),
• Buying the two consecutive emeralds with size (sum = ), or
• Buying a single emerald of size , , , or .