AmazonOA #262
Maximize Final Element
估计中等可在线判题
You may rearrange the array arbitrarily and decrease elements to integers of at least 1. The final first element must be 1, and a[i]−a[i−1]≤1 must hold for i≥1; find the maximum value of the last element. This is a one-sided difference condition, and the original array need not be sorted.
输入格式
The first line contains n; the second line contains the array. The original text had no numeric bounds; this site uses 1≤n≤200000, 1≤element≤10^9.
输出格式
Output a single integer, the answer.
样例 1
输入:
4
3 1 3 4
输出:
4
样例 2
输入:
1
100
输出:
1
样例 3
输入:
3
1 1 10
输出:
2
样例说明
The answers are 4, 1 and 2. A single element must become 1; you cannot simply take the maximum as the answer.