| Codeforces Round 1136 (Div. 1) |
|---|
| Finished |
Deep beneath Gensokyo lies the Former Hell. Satori Komeiji, the mistress of the Palace of the Earth Spirits, has opened a new metro line leading from the surface entrance to the palace. The line has $$$n$$$ stations numbered $$$1, 2, \ldots, n$$$ in order. If a train stops at station $$$i$$$, it spends $$$a_i$$$ units of time there. Exactly two trains operate on this line.
For every pair of stations $$$u \lt v$$$, there exists at least one passenger who wants to travel from $$$u$$$ to $$$v$$$. The passenger behaves as follows.
Satori may decide, independently for the two trains, which stations each train stops at. She wants to minimize the maximum travel time over all passengers. Output that minimum possible value.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$).
The second line of each case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
For each test case, output a single integer — the minimum possible maximum travel time.
441 2 3 441 1 1 125 751 10 10 10 1
731222
In the first two test cases, an optimal arrangement is to make one train stop at every station and the other train stop only at stations $$$\{1, 2, 4\}$$$.
In the first test case, the maximum travel time is then $$$7$$$: it is attained by the passenger travelling from $$$3$$$ to $$$4$$$ on the first train and by the passenger travelling from $$$1$$$ to $$$4$$$ on the second train.
In the second test case, the maximum travel time is $$$3$$$, attained, for example, by the passenger travelling from $$$1$$$ to $$$3$$$ on the first train and by the passenger travelling from $$$1$$$ to $$$4$$$ on the second train.
In the third test case, the line has only two stations, so both trains stop at both of them, and the only passenger travels from $$$1$$$ to $$$2$$$: the answer is $$$a_1 + a_2 = 12$$$.
| Name |
|---|


