B. roadside Trees (Simplified Edition) time limit per test 2 secondsmemory limit per test 256 megabytesinput standard inputoutput standard output has n Trees from west to east, numbered 1 to n, and the tree has nuts at the top. I tree height hi. liss wants to eat all nuts. liss is 1 in the height of the 1st trees. liss takes 1 s to do any of the following: Move 1 cell above or below the tree. eat nut on the top of the tree. jump to the east side of the tree (cannot jump to the west), the height remains unchanged, note that Liss cannot jump from the high to the low. Calculate the shortest time for Liss to eat all nuts. the first behavior of Input is n (1 rows less than or equal to limit less than n rows less than or equal to limit 105 ). the next n behavior sequence hi (1 Gbit/s ≤ Gbit/s hi Gbit/s ≤ Mbit/s 104 ). output calculates the shortest time for Liss to eat all nuts. sample test (s) input212output5input521211output14 note that you cannot jump to the west. (I thought it was okay at first. Check the question carefully !) [Cpp] # include <cstdio> # include <iostream> # include <cstdlib> # include <cstring> # include <cmath> # include <functional> # include <algorithm> # include <cctype> using namespace std; # define MAXN (100000 + 10) # define MAXHi (10000 + 10) int n, h [MAXN]; int main () {www.2cto.com cin> n; for (int I = 1; I <= n; I ++) cin> h [I]; h [0] = 1; int ans = 0; for (int I = 1; I <= n; I ++) ans + = abs (h [I]-h [I-1]); /* int hmin = h [n]; for (int I = n-1; I> = 1; I --) {ans = min (ans, ans-abs (h [I]-h [I-1])-abs (h [I + 1]-h [I]) + abs (h [I-1]-h [I + 1]) + n-I + abs (hmin-h [I]) + abs (hmin-h [n]);} */ans + = 2 * n; cout <ans <endl; return 0 ;}