問題一覧 > 通常問題

No.77 Brick Pyramid

レベル : / AI推定難易度 : 650 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 246
作問者 : yuki2006
お気に入りにしたユーザー ProblemId : 186 / 自分の提出
問題文最終更新日: 2026-06-25 06:02:00
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 58 (順位表) の他の問題:

Problem Statement

Vega wants to build a flat pyramid out of bricks.

In the garden, $N$ columns of bricks are already stacked with no gaps, and the number of bricks stacked in the $i$-th column is $A_i$.
Starting from this initial arrangement, Vega wants to move some of the bricks and rearrange them into a pyramid arrangement.

A pyramid arrangement is an arrangement that starts from $1$ and increases by 1 up to the center position and decreases by 1 after the center, like $[1,2,3,4,3,2,1]$.
(That is, the number of columns in a pyramid arrangement is odd.)

Separately from the pyramid, there is also a discard area, where bricks not used in the pyramid arrangement can be placed.

A move consists of taking one brick from the top of any column and moving it either to another column or to the discard area.
Here, the pyramid arrangement starts at the position of the bricks in the 1st column of the initial arrangement.
The result may have more columns than the given number of columns.
Find the minimum number of moves needed to reach a pyramid arrangement that can be formed by moving 0 or more bricks from the initial arrangement.


Assume that there is only one pyramid at the pyramid location and that all unneeded bricks are moved to the discard area.
All bricks are cubes of the same size.

Input

$N$
$A_1\,A_2\,\cdots\,A_N$

All inputs are given as integers.
$1\le N \le 100 $
$1\le A_i \le 100 $

Output

Output the minimum number of moves to reach a pyramid arrangement.
Print a newline at the end.

Sample

Sample 1
Input
5
2 2 2 1 2
Output
2

Moving a block from the 1st column to the 3rd column and a block from the 5th column to the 4th column gives a pyramid arrangement, so moving 2 blocks results in a pyramid arrangement.

Sample 2
Input
3
3 2 3
Output
4

Moving 4 bricks to the discard area gives a pyramid arrangement.

Sample 3
Input
9
1 1 1 1 1 1 1 1 1
Output
4

Sample 4
Input
3
1 2 1
Output
0

It is already a pyramid arrangement.

Sample 5
Input
1
4
Output
3

Even when there is only one column initially, a pyramid with 3 columns can be built by moving 3 bricks.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。