T1
CF1749B
题目描述
You are playing a computer game. To pass the current level, you have to kill a big horde of monsters. In this horde, there are nn monsters standing in the row, numbered from 11 to nn . The ii -th monster has a_iai health and a special "Death's Blessing" spell of strength b_ibi attached to it.
You are going to kill all of them one by one. It takes exactly hh seconds to kill a monster with health hh .
When the ii -th monster dies, it casts its spell that increases the health of its neighbors by b_ibi (the neighbors of the jj -th monster in the row are the monsters on places j - 1j−1 and j + 1j+1 . The first and the last monsters have only one neighbor each).
After each monster is killed, the row shrinks, so its former neighbors become adjacent to each other (so if one of them dies, the other one is affected by its spell). For example, imagine a situation with 44 monsters with health a = [2, 6, 7, 3]a=[2,6,7,3] and spells b = [3, 6, 0, 5]b=[3,6,0,5] . One of the ways to get rid of the monsters is shown below:
22 66 77 33 \xrightarrow{6\ s}6 s 88 1313 33 \xrightarrow{13\ s}13 s 88 33 \xrightarrow{8\ s}8 s 66 \xrightarrow{6\ s}6 s \{\}{} 33 66 00 55 33 00 55 33 55 55 The first row represents the health of each monster, the second one — the power of the spells.As a result, we can kill all monsters in 6 + 13 + 8 + 66+13+8+6 == 3333 seconds. Note that it's only an example and may not be the fastest way to get rid of the monsters.
What is the minimum time required to kill all monsters in the row?
输入格式
The first line contains a single integer tt ( 1 \le t \le 10^41≤t≤104 ) — the number of test cases.
The first line of each test case contains a single integer nn ( 1 \le n \le 2 \cdot 10^51≤n≤2⋅105 ) — the number of monsters in the row.
The second line contains nn integers a_1, a_2, \dots, a_na1,a2,…,an ( 1 \le a_i \le 10^91≤ai≤109 ) — the initial health of corresponding monsters.
The third line contains nn integers b