QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100 Hackable ✓

#16163. Building Blocks Competition

Statistics

The Chun-Chun Kindergarten is holding its annual "Building Block Competition." This year's competition involves building a skyscraper of width $n$. The skyscraper can be viewed as being composed of $n$ blocks, each of width 1, where the final height of the $i$-th block needs to be $h_i$.

Before building begins, there are no blocks (which can be viewed as $n$ blocks of height 0). In each subsequent operation, the children can choose a continuous interval $[L, R]$ and increase the height of all blocks from the $L$-th to the $R$-th (inclusive) by 1.

Xiao M is a clever child who quickly figured out the optimal strategy to build the skyscraper with the minimum number of operations. However, she is not a child who likes to do manual labor, so she asks you to implement this strategy and find the minimum number of operations required.

Input

The input consists of two lines. The first line contains a single integer $n$, representing the width of the skyscraper. The second line contains $n$ integers, where the $i$-th integer is $h_i$.

Output

Output a single line containing the minimum number of operations required to build the skyscraper.

Examples

Input 1

5
2 3 4 1 2

Output 1

5

Note

One possible optimal strategy is to choose the following intervals in sequence: $[1, 5], [1, 3], [2, 3], [3, 3], [5, 5]$

Constraints

For 30% of the data, $1 \le n \le 10$; For 70% of the data, $1 \le n \le 1000$; For 100% of the data, $1 \le n \le 100000$, $0 \le h_i \le 10000$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.