103681: [Atcoder]ABC368 B - Decrease 2 max elements
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:4
Solved:0
Description
Score : $200$ points
Problem Statement
You are given a sequence of $N$ positive integers $A = (A_1, A_2, \dots ,A_N)$. Takahashi repeats the following operation until $A$ contains one or fewer positive elements:
- Sort $A$ in descending order. Then, decrease both $A_1$ and $A_2$ by $1$.
Find the number of times he performs this operation.
Constraints
- $2 \leq N \leq 100$
- $1 \leq A_i \leq 100$
- All input values are integers.
Input
The input is given from Standard Input in the following format:
$N$ $A_1$ $A_2$ $\cdots$ $A_N$
Output
Print the answer.
Sample Input 1
4 1 2 3 3
Sample Output 1
4
The process goes as follows:
- After the 1st operation, $A$ is $(2, 2, 2, 1)$.
- After the 2nd operation, $A$ is $(1, 1, 2, 1)$.
- After the 3rd operation, $A$ is $(1, 0, 1, 1)$.
- After the 4th operation, $A$ is $(0, 0, 1, 0)$. $A$ no longer contains more than one positive elements, so the process ends here.
Sample Input 2
3 1 1 100
Sample Output 2
2
Output
得分:200分
问题陈述
给你一个由N个正整数构成的序列A = (A_1, A_2, …, A_N)。高桥重复以下操作,直到A中只剩一个或更少的正数元素:
- 将A按降序排序。然后,将A_1和A_2都减少1。
找出他执行此操作的次数。
约束条件
- 2 ≤ N ≤ 100
- 1 ≤ A_i ≤ 100
- 所有输入值都是整数。
输入
输入从标准输入以下格式给出:
$N$ $A_1$ $A_2$ $…$ $A_N$
输出
打印答案。
示例输入1
4 1 2 3 3
示例输出1
4
过程如下:
- 第1次操作后,A变为(2, 2, 2, 1)。
- 第2次操作后,A变为(1, 1, 2, 1)。
- 第3次操作后,A变为(1, 0, 1, 1)。
- 第4次操作后,A变为(0, 0, 1, 0)。A不再包含一个以上的正数元素,所以过程在这里结束。
示例输入2
3 1 1 100
示例输出2
2