题目描述
Problem Description
There are a total of $n$ apples, and you want to choose exactly two of them.
Each apple has a nutritional value $a_1, a_2, \cdots, a_n$. You need to choose one with the highest nutritional value for gza to eat, and one with the lowest nutritional value for gza's friend azg to eat.
Note that due to issues like worm infestation, the nutritional values may be negative. Even in such cases, you must choose exactly two apples.
The price you need to pay is the sum of the nutritional values of the two chosen apples. Please output the price you need to pay.
Input Format
The first line contains an integer $n$, representing the number of apples.
The second line contains $n$ integers $a_1, \cdots, a_n$, representing the nutritional values of the $1st, 2nd, \cdots,$ apples.
Output Format
A single line containing an integer, representing the price you need to pay.
Sample Input and Output
Sample Input #1
5
1 6 3 6 2
Sample Output #1
7
Sample Input #2
3
2000000000 1000000000 1000000000
Sample Output #2
3000000000
Sample Input #3
5
-21789523 -1 -3 -7 -2578928
Sample Output #3
-21789524
Notes
Sample 1 Explanation
The apple with the highest nutritional value is the second (or fourth) apple, and the one with the lowest nutritional value is the first apple. The price is $6 + 1 = 7$.
Sample 3 Explanation
The apple with the highest nutritional value is the second apple, and the one with the lowest nutritional value is the first apple. The price is $(-1) + (-21789523) = -21789524$.
Data Size and Constraints
For $100\%$ of the data, $2 \leq n \leq 10^5$, $-2 \times 10^9 \leq a_i \leq 2 \times 10^9$.
| Test Case Number | $n$ | $a_i$ | Special Properties |
|---|---|---|---|
| $1, 2$ | $\leq 10$ | $1 \leq a_i \leq 100$ | None |
| $3, 4$ | $\leq 100$ | $-10^4 \leq a_i \leq 10^4$ | None |
| $5$ | $\leq 10^5$ | $-2 \times 10^9 \leq a_i \leq 2 \times 10^9$ | All $a_i$ are the same |
| $6, 7$ | $\leq 10^5$ | $-2 \times 10^9 \leq a_i \leq 2 \times 10^9$ | $a_1 \leq a_2 \leq \cdots \leq a_n$ |
| $8 \sim 10$ | $\leq 10^5$ | $-2 \times 10^9 \leq a_i \leq 2 \times 10^9$ | None |
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分