시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB36191862.069%

문제

The arts and crafts teacher is looking at the beautiful plank you crafted in the woodshop, and gaze at you with a stern look. "This is not smooth enough! Use more sandpaper!"

Your plank is $n$ cm long, and the arts and crafts teacher has measured the width of your plank on $k$ different locations to prove his point. He demands that the thickness should differ by no more than $1$ micrometer between any two consecutive measured location. If the sandpaper will shave off $1$ micrometer of wood each time you use it at a particular location, how many times do you need to use the sandpaper?

입력

The first line of input contains a single integer $1 \leq n \leq 10^6$, the length of your plank. On the second line of input follows $n$ space-separated integers $k_1, k_2, \ldots, k_n$, the thickness of your plank ($1 \leq k_i \leq 10^6$ for every $i$).

출력

Output a single integer, the minimum number of times you need to use the sandpaper (assuming that the sandpaper only touch one location at the same time).

예제 입력 1

5
1 6 7 2 5

예제 출력 1

10

출처

Contest > Bergen Open > Bergen Open 2021 M번

  • 문제를 만든 사람: Torstein Strømme