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 Ai or Bi. 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 Ai, and the piece used for the gate will have a beauty value of Bi. 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 Ai. - The third line contains n integers Bi. ### Output - Output n integers, where the i-th integer represents the maximum beauty value when Marisa uses i pieces of wood. ### Constraints - 1≤n≤105. - 1≤Ai,Bi≤109. ### Example Input: 21221 Output: 24