| UTPC Spring 2024 Open Contest |
|---|
| Finished |
Alice and Bob are tired of listening to records all day, so they decided to get food. Of course there is no better place to get food than at the Unlimited Topping Pizza Cafe (UTPC).
At the UTPC, every pizza is represented by a set of toppings arranged in a circle. Specifically, there are $$$n$$$ positions on the pizza, numbered from $$$1$$$ to $$$n$$$. Each topping has a tastiness value in the range $$$[1, 100]$$$, and each position on a pizza may contain up to two toppings (possibly none). It is well-known that if two toppings line on the same position of a pizza, they will no longer have any tastiness, so the tastiness of a pizza is defined as the sum of tastiness of all toppings on the pizza which do not share a position with any other topping.
This is both Alice's and Bob's first time visiting the UTPC, and they have a dilemma: They each have a pizza in mind (which contains at most one topping at each position), but can only afford to purchase one (the pizzas here are quite expensive). You, the chef, know how to solve the dilemma: by merging the two pizzas into one! First, you will rotate Bob's pizza by some amount so that each position in Bob's pizza is aligned with some position in Alice's pizza. Then, you will transfer all of Bob's toppings to the corresponding position on Alice's pizza. Since you want Alice and Bob to return in the future, you must find the maximum tastiness which a pizza can contain after merging Alice's and Bob's pizzas.
The first line of input consists of a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the number of positions on each pizza.
The second line of input consists of $$$n$$$ space-separated integers $$$a_1, \dots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the toppings on Alice's pizza. If $$$a_i = 0$$$, then there is no topping at position $$$i$$$. Otherwise, $$$a_i$$$ represents the tastiness of the topping at position $$$i$$$.
Similarly, the third line consists of $$$n$$$ space-separated integers $$$b_1, \dots, b_n$$$ ($$$0 \leq b_i \leq 100$$$) — the toppings on Bob's pizza. If $$$b_i = 0$$$, then there is no topping at position $$$i$$$. Otherwise, $$$b_i$$$ represents the tastiness of the topping at position $$$i$$$.
The output consists of a single integer — the maximum possible tastiness of the merged pizza.
51 3 0 0 12 0 1 0 0
6
81 4 11 3 0 0 0 12 0 0 0 6 0 5 3
29
31 1 11 1 1
0
In the first sample, Alice and Bob have the following two pizzas in mind:
We can obtain a pizza with a tastiness of $$$6$$$ by rotating Bob's pizza twice clockwise relative to Alice's pizza as seen below:
The tastiness of this pizza is $$$1 + 3 + 2 = 6$$$ since that is the sum of the toppings which are in a position of their own.
| Name |
|---|


