#P16566. [ICPC 2026 APC] Reflect Sort
[ICPC 2026 APC] Reflect Sort
题目描述
You have a sequence of integers , the initial values of which are given to you. You may apply the following operation to the sequence any number of times (possibly zero):
- Choose an index ( ).
- Choose a set to be either the prefix or the suffix .
- For every , replace with .
Your goal is to make the sequence non-decreasing and all elements positive, while minimizing , using the operation above any number of times. That is, must hold in the resulting sequence. What is the minimum possible value of in the resulting sequence?
输入格式
The first line of input contains a single integer ( ).
The second line contains integers representing the initial values of ( ).
输出格式
Output the minimum possible value of in the resulting sequence.
5
6 3 5 5 2
10
3
2 1 100000
100002
提示
Explanation for the sample input/output #1
You can do the following sequence of operations.
- Choose and as the suffix : .
- Choose and as the prefix : .
- Choose and as the prefix : .
After these operations, the sequence is non-decreasing and all elements are positive. It can be shown that is the minimum possible value.
Explanation for the sample input/output #2
The minimum possible value of is , which can be attained by the following operations.
- Choose and as the suffix : .
- Choose and as the suffix : .
Note that the sequence may contain non-positive values during operations.