#P10067. [CCO 2023] Real Mountains
[CCO 2023] Real Mountains
Problem Description
With your help, Rebecca’s landscape photo has made it onto the cover of the latest issue of her magazine. However, some readers still seem unhappy with the photo. In particular, they think the mountains in the photo are fake.
For simplicity, we can describe the photo as a sequence of columns of pixels. In column , the bottom pixels are mountain. Her readers will only believe this is a real mountain if the photo contains a single peak. That is, if there exists an index with such that $h_{1} \leq h_{2} \leq \cdots \leq h_{p} \geq \cdots \geq h_{N-1} \geq h_{N}$.
Luckily, Rebecca can also pay her editors to modify the photo and reprint the magazine. Unfortunately, the editors have a very strange pricing scheme for their work. The only way Rebecca can edit the photo is to send her editors an email containing three integers satisfying and . The editors will add one extra mountain pixel to column (i.e., increase by ), at a cost of . Note that changes to may affect the cost of future edits.
To satisfy her readers, Rebecca wants to edit the photo so that they believe there is a real mountain here. Can you tell her the minimum total cost required?
Input Format
The first line contains an integer .
The second line contains space-separated integers, denoting .
Output Format
Output , where is the minimum total cost Rebecca needs to pay to satisfy her readers.
8
3 2 4 5 4 1 2 1
14
Hint
Rebecca can send two emails. The first contains , and the second contains . The first email costs and increases by , and the second email costs and increases by .
In the end, the values in the photo will be .
For all testdata, and .
| Subtask ID | Score | Range of | Range and constraints on |
|---|---|---|---|
| 1 | 12 | $1 \leq h_{i} \leq 100, \exists p \in [1,N], h_{1} \geq h_{2} \geq \cdots \geq h_{p} \leq \cdots \leq h_{N-1} \leq h_{N}$ | |
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | 16 | ||
| 6 | 20 | ||
| 7 | 16 |
Translated by ChatGPT 5