AtCoder Beginner Contest 116
C
Grand Garden
AtCoder
⌀ 542
原题
← BD →
翻译中…

Problem Statement

翻译中…

In a flower bed, there are $N$ flowers, numbered $1,2,......,N$. Initially, the heights of all flowers are $0$. You are given a sequence $h=\{h_1,h_2,h_3,......\}$ as input. You would like to change the height of Flower $k$ to $h_k$ for all $k$ $(1 \leq k \leq N)$, by repeating the following "watering" operation:

翻译中…
  • Specify integers $l$ and $r$. Increase the height of Flower $x$ by $1$ for all $x$ such that $l \leq x \leq r$.
翻译中…

Find the minimum number of watering operations required to satisfy the condition.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 100$
  • $0 \leq h_i \leq 100$
  • All values in input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
h_1 h_2 h_3 ...... h_N

翻译中…

Output

翻译中…

Print the minimum number of watering operations required to satisfy the condition.

翻译中…

样例

Input #1
4
1 2 2 1
Output #1
2
The minimum number of watering operations required is $2$. One way to achieve it is: - Perform the operation with $(l,r)=(1,3)$. - Perform the operation with $(l,r)=(2,4)$.
Input #2
5
3 1 2 3 1
Output #2
5
Input #3
8
4 23 75 0 23 96 50 100
Output #3
221
题目信息
题号
abc116_c
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。