No.77 Brick Pyramid
タグ : / 解いたユーザー数 246
作問者 :
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もしくは右上の雲マークをクリックしてアカウントを作成してください。