Canadian Computing Competition: 2015 Stage 1, Senior #5
The local pie shop is offering a promotion - all-you-can-eat pies! Obviously, you can't pass up this offer.
The shop lines up
You are first allowed to insert each of the
Following this, you are allowed to take one walk along the new line of pies from left to right, to pick up your selection of all-you-can-eat pies! When you arrive at a pie, you may choose to add it to your pile, or skip it. However, because you're required to keep moving, if you pick up a certain pie, you will not be able to also pick up the pie immediately after it (if any). In other words, you cannot eat consecutive pies in this combined list.
Being a pie connoisseur, your goal is to maximize the total amount of sugar in the pies you pick up from the line. How many grams can you get?
Input Specification
The first line of input contains the integer
The next line contains
For
Output Specification
Output the maximum number of grams of sugar in all the pies that you are able to pick up.
Sample Input
5
10
12
6
14
7
3
1
8
2
Output for Sample Input
44
Explanation of Output for Sample Input
Place the pies in the order
(that is, insert the pie with
Comments
The successor to pi day.