AmazonOA #9
Outlier Value
估计中等可在线判题
In the array, n−2 elements are normal numbers, and two other distinct indices hold the sum of the normal numbers and the outlier, respectively. Find the largest outlier over all valid choices. The sum element and the outlier may have the same value but must be at different indices. A valid choice is guaranteed to exist. The source example [4,1,2,10] does not fit the definition; this site uses a valid example instead and verified it independently.
输入格式
The first line contains n (3..100000), and the second line contains n positive integers (1..10⁹); at least one valid choice is guaranteed to exist.
输出格式
Output a single integer, the answer required by the problem.
样例 1
输入:
4
4 1 2 3
输出:
4
样例 2
输入:
3
1 1 1
输出:
1
样例 3
输入:
4
2 3 5 10
输出:
10
样例说明
Example 1: the normal numbers are 1 and 2, the sum element is 3, and the outlier is 4. Example 2: three distinct indices serve as the normal number, the sum element, and the outlier respectively; even though all values are 1, this is still valid. Example 3: the sum of the normal numbers 2 and 3 is 5, and the remaining 10 is the outlier, which is also the array maximum.