题目描述
Problem Description
Given a sequence of positive integers $A = (A_1, A_2, \dots, A_N)$ of length $ N $. Takahashi will repeat the following operation until the number of positive elements in $ A $ is reduced to 1 or less:
- Sort $ A $ in descending order. Then, decrease $ A_1 $ and $ A_2 $ by 1.
Find the number of times Takahashi performs the operation.
Input Format
The input is given from the standard input in the following format:
$ N $ $ A_1 $ $ A_2 $ $\cdots$ $ A_N $
Output Format
Output the answer.
Sample Input and Output
Sample Input #1
4
1 2 3 3
Sample Output #1
4
Sample Input #2
3
1 1 100
Sample Output #2
2
Notes/Hints
Constraints
- $2 \leq N \leq 100$
- $1 \leq A_i \leq 100$
- All inputs are integers
Sample Explanation 1
The operations proceed as follows:
- After the 1st operation, $ A = (2, 2, 2, 1) $.
- After the 2nd operation, $ A = (1, 1, 2, 1) $.
- After the 3rd operation, $ A = (1, 0, 1, 1) $.
- After the 4th operation, $ A = (0, 0, 1, 0) $. The number of positive elements in $ A $ is reduced to 1 or less, so the operations end here.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分