题库练习 Chess Placing
← 上一题 下一题 →

A11839 | Chess Placing

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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
C++ 编辑器
输入
输出