아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Meticulous smoothing

면접 대비

시간 제한1초메모리 제한1024 MB

요약
판자의 n개 위치 두께가 주어질 때, 인접한 위치의 두께 차이가 1 이하가 되도록 깎으면서 제거하는 목재의 최소량을 구한다.
난이도

보통10점 중 5점

유형
배열, 그리디, 수학
정답자
아직 제출이 없습니다

문제

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 nn cm long, and the arts and crafts teacher has measured the width of your plank on kk different locations to prove his point. He demands that the thickness should differ by no more than 11 micrometer between any two consecutive measured location. If the sandpaper will shave off 11 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≤n≤1061 \leq n \leq 10^6, the length of your plank. On the second line of input follows nn space-separated integers k_1,k_2,…,k_nk\_1, k\_2, \ldots, k\_n, the thickness of your plank (1≤k_i≤1061 \leq k\_i \leq 10^6 for every ii).

출력

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

  1. 예제 1

    입력
    5
    1 6 7 2 5
    
    예상 출력
    10