加载中...

AtCoder题解|Grand Garden


本篇博客还在持续修改润色中~

敬请期待~

AtCoder题解|ABC 116C Grand Garden


题目信息 📚

【题目描述】

In a flower bed, there are $N$ flowers, numbered $1, 2, \ldots, N$. Initially, the heights of all flowers are $0$. You are given a sequence $h = {h_1, h_2, h_3, \ldots}$ 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.

【输入】

Input is given from Standard Input in the following format:

$N$

$h_1$ $h_2$ $h_3$ $\dots$ $h_N$

【输出】

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

【数据范围】

  • $1 \leq N \leq 100$
  • $0 \leq h_i \leq 100$
  • All values in the input are integers.

【输入样例1】

4
1 2 2 1

【输出样例1】

2

The minimum number of watering operations required is $2$. One way to achieve it is:

  1. Perform the operation with $(l, r) = (1, 3)$.
  2. Perform the operation with $(l, r) = (2, 4)$.

【输入样例2】

5
3 1 2 3 1

【输出样例2】

5

【输入样例3】

8
4 23 75 0 23 96 50 100

【输出样例3】

221

【题目来源】

https://atcoder.jp/contests/abc116/tasks/abc116_c


题目解析 🍉

【题目分析】

【C++代码】


文章作者: Rickyの水果摊
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Rickyの水果摊 !
  目录