Building fence - MarisaOJ: Marisa Online Judge

Building fence

Time limit: 1000 ms
Memory limit: 256 MB
Marisa has $n$ pieces of wood and wants to use them to make a fence. The $i$-th piece of wood has a beauty value of either $A_i$ or $B_i$. If Marisa chooses $k$ pieces of wood to make a fence around her house, she will choose $k-1$ pieces to build the fence and $1$ piece to make the gate. In this case, the pieces used for the fence will have a beauty value of $A_i$, and the piece used for the gate will have a beauty value of $B_i$. For each value of $k$ from $1$ to $n$, help Marisa calculate the maximum beauty value she can achieve. ### Input - The first line contains an integer $n$. - The second line contains $n$ integers $A_i$. - The third line contains $n$ integers $B_i$. ### Output - Output $n$ integers, where the $i$-th integer represents the maximum beauty value when Marisa uses $i$ pieces of wood. ### Constraints - $1 \le n \le 10^5$. - $1 \le A_i, B_i \le 10^9$. ### Example Input: ``` 2 1 2 2 1 ``` Output: ``` 2 4 ```