RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 ICPC00086

B. Bulldozer

설명

You are tasked with bulldozing some buildings that stand along a long, straight road. The buildings are modelled as evenly spaced stacks of identical square blocks along an infinite line. Your powerful bulldozer is capable of moving any one of these blocks one unit of distance to the left or to the right. This may push other blocks out of the way, and blocks which sit atop moving blocks will move along. Blocks which are pushed over a gap fall down until they reach either the ground or another block.

For instance, consider the stacks of blocks shown on the left in Figure below. If you push the block labelled C to the right, the blocks D and E would be pushed along to the right, since they are in the way. Blocks A, B and F would also move along because they are sitting on top of moving blocks. After pushing C to the right, E would be sitting over a gap, so E and F drop down to fill that gap. The resulting stacks are shown in the middle of Figure . Pushing block C one further step to the right would result in the configuration shown on the right.

Your goal is to level all the buildings: bulldoze until all stacks are of height at most \(1\), i.e., all blocks are on the ground. Note that the road stretches out infinitely far on either side, so this is always possible.

Given the initial heights of the stacks, determine the smallest number of moves you need to make to level all the buildings, where a move consists of using the bulldozer to push one block one step to the left or right.

제약
입력 형식

The input consists of:
- One line with an integer \(n\) (\(1 \le n \leq 2 \cdot 10^5\)), the number of stacks of blocks.
- One line with \(n\) integers \(a_1, \ldots, a_n\) (\(0 \leq a_i \leq 10^9\) for each \(i\)), the initial heights of the stacks from left to right.

The example shown on the left in Figure could be given by \(3, 5, 3, 4, 1, 1, 0, 0, 1, 1\), but it could also be left- or right-padded with additional zeros.

출력 형식

Output the minimum number of moves required to level every building.

예제 1
입력
5
1 1 2 1 1
출력
2
예제 2
입력
5
1 4 3 1 1
출력
7
예제 3
입력
9
1 0 0 0 6 0 0 0 1
출력
5
예제 4
입력
10
1 3 0 0 1 9 1 1 1 1
출력
13
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC NWERC 2020

평가 및 의견

B. Bulldozer

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

B. Bulldozer

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8