You are given an integer $$$n$$$ and a target array $$$a = [a_1, a_2, \dots, a_n]$$$. Initially, you have an array $$$b$$$ of length $$$n$$$ with all elements equal to $$$0$$$.
In one operation, you select a segment $$$[l, r]$$$ ($$$1 \le l \le r \le n$$$) and positive $$$x$$$, and add $$$x$$$ to each element in that segment: $$$b[i] = b[i] + x$$$ for all $$$i$$$ in range $$$[l, r]$$$
Determine the minimum number of operations required to transform array $$$b$$$ into array $$$a$$$.
Constraints:
$$$ 1 \lt = n \lt = 10^5 $$$
$$$ 0 \lt = a_i \lt = 10^9$$$
$$$ x \gt 0 $$$
I think a is to compute the sum of positive differences between adjacent elements: $$$ans$$$ $$$+=$$$ $$$\sum_{i = 1}^n $$$ $$$max(a_i - a_{i - 1}, 0)$$$ where we set $$$a_0 = 0$$$. However, this approach only works when $$$x = 1$$$.
Thank in advanced



