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 pies from left to right - the pie contains grams of sugar. Additionally, another pies are provided - the of these contains grams of sugar.
You are first allowed to insert each of the pies from the second group anywhere into the first list of pies, such as at its start or end, or in between any two pies already in the list. The result will be a list of pies with the constraint that the initial pies are still in their original relative order.
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?
The first line of input contains the integer (). The next lines contain one integer (), describing the integer number of grams of sugar in pie in the group of pies.
The next line contains (), the number of pies in the second list. The next lines contain one integer (), describing the integer number of grams of sugar in pie in the group of pies.
For of the marks for this question, . For another of the marks for this question . For another of the marks for this question .
Output the maximum number of grams of sugar in all the pies that you are able to pick up.
5 10 12 6 14 7 3 1 8 2
Output for Sample Input
Explanation of Output for Sample Input
Place the pies in the order
(that is, insert the pie with gram of sugar between and , and insert pies with and grams of sugar, in that order, between pies and ). Then, we can grab grams of sugar, which is maximal.