测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A11839. Chess Placing

编程题 普及/提高-

题目描述

You are given a chessboard of size $1×n$ . It is guaranteed that $n$ is even. The chessboard is painted like this: "BWBW $...$ BW".

Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to ![](/uploads/acgo/image/77659388009918a2_cd0792384f53.jpeg).

In one step you can move one of the pieces one cell to the left or to the right. You cannot move pieces beyond the borders of the board. You also cannot move pieces to the cells that are already occupied.

Your task is to place all the pieces in the cells of the same color using the minimum number of moves (all the pieces must occupy only the black cells or only the white cells after all the moves are made).

输入格式

The first line of the input contains one integer $n$ ( $2<=n<=100$ , $n$ is even) — the size of the chessboard.

The second line of the input contains ![](/uploads/luogu/CF985A/e98ace5c1ad627053f6404505602ba90672a171b_985d0f7ec134.png) integer numbers ![](/uploads/acgo/image/9347a361b01a62e2_d0a31f9b33cf.jpeg) ( $1<=p_{i}<=n$ ) — initial positions of the pieces. It is guaranteed that all the positions are distinct.

输出格式

Print one integer — the minimum number of moves you have to make to place all the pieces in the cells of the same color.

输入输出样例

输入 #1
6
1 2 6
输出 #1
2
输入 #2
10
1 2 3 4 5
输出 #2
10

说明/提示

In the first example the only possible strategy is to move the piece at the position $6$ to the position $5$ and move the piece at the position $2$ to the position $3$ . Notice that if you decide to place the pieces in the white cells the minimum number of moves will be $3$ .

In the second example the possible strategy is to move ![](/uploads/luogu/CF985A/4f3653422b6429c3f89311497c438fd20547c4f8_22127fe11eca.png) in 4 moves, then ![](/uploads/luogu/CF985A/6c4181624e2b8f95750df668d534111d8ee2005d_21a2a5923899.png) in 3 moves, ![](/uploads/luogu/CF985A/74a8630d5d683f941562dca49b5d40bcde2fe1ef_135d54cb04a8.png) in 2 moves and ![](/uploads/acgo/image/047b2df38ce1a058_b46b8f39b273.jpeg) in 1 move.
上一题 去做题 下一题