Codeforces Round 953 (Div. 2)
A
Alice and Books
Codeforces
800
原题
←B →
翻译中…

Alice has $n$ books. The $1$-st book contains $a_1$ pages, the $2$-nd book contains $a_2$ pages, $\ldots$, the $n$-th book contains $a_n$ pages. Alice does the following:

翻译中…
  • She divides all the books into two non-empty piles. Thus, each book ends up in exactly one of the two piles.
  • Alice reads one book with the highest number in each pile.
翻译中…

Alice loves reading very much. Help her find the maximum total number of pages she can read by dividing the books into two piles.

翻译中…

Input

翻译中…

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 500$) — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($2 \le n \le 100$) — the number of books Alice has.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — the number of pages in each book.

翻译中…

Output

翻译中…

For each test case, output a single integer — the maximum number of pages Alice can read.

翻译中…

Note

翻译中…

In the first test case, Alice can put book number $1$ in the first pile, and book number $2$ in the second pile. Then she will read $a_1 + a_2 = 1 + 1 = 2$ pages.

翻译中…

In the second test case, Alice can put books with numbers $2$ and $3$ in the first pile, and books with numbers $1$ and $4$ in the second pile. Then she will read the book with the highest number $3$ from the first pile, and the book with the highest number $4$ from the second pile. Then she will read $a_3 + a_4 = 3 + 1 = 4$ pages.

翻译中…

样例

Input #1
5
2
1 1
4
2 3 3 1
5
2 2 3 2 2
2
10 3
3
1 2 3
Output #1
2
4
5
13
5
InputCopy OutputCopy
题目信息
题号
1978A
时间限制
1 s
内存限制
256 MB
标签
构造
贪心
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。