No.110 Striped Pyramid
Problem Statement
There are some white and black blocks of different lengths.
You want to build a pyramid by stacking blocks horizontally from the bottom up.
However, the following conditions apply.
・A block placed on top must be shorter than the block below it.
・The colors of the stacked blocks must alternate between white and black.
Each block stacked increases the height by 1.
What is the height of the tallest pyramid that can be built under these conditions?
Input
$N_w$
$W_1$ $W_2$ ... $W_{Nw}$
$N_b$
$B_1$ $B_2$ ... $B_{Nb}$
The number of white blocks $N_w$ is given. ($1 \le N_w \le 10$)
The lengths $Wi$ of the $i$-th white blocks are given on one line as $Nw$ values separated by spaces. ($1 \le W_i \le 20$)
The number of black blocks $N_b$ is given. ($1 \le N_b \le 10$)
The lengths $B_i$ of the $i$-th black blocks are given on one line as $Nb$ values separated by spaces. ($1 \le B_i \le 20$)
Output
Output the maximum height of a pyramid that can be built, on one line.
Do not forget the newline at the end.
Sample
Sample 1
Input
2 1 3 1 2
Output
3
There are white blocks of lengths 1 and 3 and a black block of length 2.
First, place the white block of length 3.
Next, place the black block of length 2.
Finally, place the white block of length 1.
This makes a pyramid of height 3.
Sample 2
Input
2 1 3 1 3
Output
2
There are white blocks of lengths 1 and 3 and a black block of length 3.
First, place the black block of length 3.
Next, place the white block of length 1.
This makes a pyramid of height 2.
Sample 3
Input
1 20 2 20 20
Output
1
There is one white block of length 20 and two black blocks of length 20.
A block of the same length cannot be stacked on top.
Therefore, you can only place a single white or black block of length 20.
It does not look like a pyramid, but this is still regarded as a pyramid of height 1.
Sample 4
Input
3 5 3 2 4 4 11 9 19
Output
4
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
nmnmnmnmnmnmnm