#P9814. [CCC 2015 S5] Greedy For Pies

[CCC 2015 S5] Greedy For Pies

Problem Description

Given a sequence aa of length nn and a sequence bb of length mm, you may insert the elements of sequence bb into sequence aa at any positions you like (including the beginning and the end). After that, you may choose some elements from the new sequence, but you are not allowed to choose two adjacent elements.

You need to maximize the sum of the chosen numbers, and output this maximum value.

Input Format

The first line contains an integer nn.

The next nn lines each contain an integer aia_{i}.

Then one line contains an integer mm.

The next mm lines each contain an integer bib_{i}.

Output Format

Output one line containing one integer, which is the maximum possible sum of elements you can choose.

5
10
12
6
14
7
3
1
8
2
44

Hint

Constraints:

For 20%20\% of the testdata, m=0m = 0.

For another 20%20\% of the testdata, m=1m = 1.

For another 20%20\% of the testdata, m10m \leq 10.

For 100%100\% of the testdata, 1n3×1031 \leq n \leq 3 \times 10^{3}, 0m1000 \leq m \leq 100, 1ai,bi1051 \leq a_{i}, b_{i} \leq 10^{5}.

Translated by ChatGPT 5