#P7404. [JOI 2021 Final] 有趣的家庭菜园 4 / Growing Vegetables is Fun 4
[JOI 2021 Final] 有趣的家庭菜园 4 / Growing Vegetables is Fun 4
Problem Description
Given a sequence of length , you may perform the following operation any number of times:
- Choose an interval and add to every number in this interval.
Let the sequence after these operations be . You need to make satisfy the following requirement:
- There exists an integer such that the subsequence is strictly increasing, and the subsequence is strictly decreasing.
You want to know the minimum number of operations needed to satisfy the requirement above.
Input Format
The first line contains an integer , representing the length of the sequence.
The second line contains integers, representing the sequence .
Output Format
Output one integer in one line, representing the minimum number of operations.
5
3 2 2 3 1
3
5
9 7 5 3 1
0
2
2021 2021
1
8
12 2 34 85 4 91 29 85
93
Hint
Explanation for Sample 1
- Perform the operation on , and the sequence becomes .
- Perform the operation on , and the sequence becomes .
- Perform the operation on , and the sequence becomes .
Explanation for Sample 2
The sequence already satisfies the requirement, so no operation is needed.
Explanation for Sample 3
It is enough to perform the operation on interval or .
Constraints
This problem uses bundled testdata.
- Subtask 1 (40 pts): .
- Subtask 2 (60 pts): No additional constraints.
For of the testdata, , .
Notes
Translated from the English statement of The 20th Japanese Olympiad in Informatics Final Round A とてもたのしい家庭菜園 4, Growing Vegetables is Fun 4.
Translated by ChatGPT 5