AtCoder Regular Contest 152
翻译中…
Problem Statement
翻译中…
We have a sequence of $N$ terms: $a_1,a_2,\ldots,a_N$. You can perform the following operation on this sequence any number of times (possibly zero).
翻译中…
- Choose a term of the sequence at that point, and let
$s$be its value. Then, for every$1\leq i\leq N$, replace$a_i$with$2s-a_i$. However, this operation may not be performed in a way that produces a term with a negative value.
翻译中…
You want to make the greatest value among the terms of the sequence as small as possible. What will this value be after an optimal sequence of operations for this objective?
翻译中…
Constraints
翻译中…
$2 \leq N \leq 2 \times 10^5$$1 \leq a_1 < a_2 < \ldots < a_N \leq 10^9$- All values in the input are integers.
翻译中…
Input
翻译中…
The input is given from Standard Input in the following format:
翻译中…
N
a_1 a_2 \ldots a_N
翻译中…
Output
翻译中…
Print the answer.
翻译中…
样例
Input #1
3
1 3 6
Output #1
5
If you perform the operation with $s=3$, the sequence becomes $(5,3,0)$. The greatest value here is $5$. Under the condition that there may not be a term with a negative value, the greatest value among the terms of the sequence cannot be made smaller, so you should print $5$.
Input #2
5
400 500 600 700 800
Output #2
400
To obtain this result, perform the operation once with $s=400$, or perform it with $s=500$ and then with $s=300$, for instance.
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。