codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

985A.md (2408B)


      1 Source: https://codeforces.com/problemset/problem/985/A
      2 
      3 A. Chess Placing
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You are given a chessboard of size 1 × *n*. It is guaranteed that *n* is even. The chessboard is painted like this: "BWBW...BW".
     22 
     23 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 ![](https://espresso.codeforces.com/a64c1b2df604f8cfa9acf6716a3cc1424488361e.png).
     24 
     25 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.
     26 
     27 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).
     28 
     29 Input
     30 
     31 The first line of the input contains one integer *n* (2 ≤ *n* ≤ 100, *n* is even) — the size of the chessboard.
     32 
     33 The second line of the input contains ![](https://espresso.codeforces.com/a64c1b2df604f8cfa9acf6716a3cc1424488361e.png) integer numbers ![](https://espresso.codeforces.com/e2af9e0bc529157633221e52aefff46b28281af2.png) (1 ≤ *p**i* ≤ *n*) — initial positions of the pieces. It is guaranteed that all the positions are distinct.
     34 
     35 Output
     36 
     37 Print one integer — the minimum number of moves you have to make to place all the pieces in the cells of the same color.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 6  
     45 1 2 6
     46 ```
     47 
     48 Output
     49 
     50 ```
     51 2
     52 ```
     53 
     54 Input
     55 
     56 ```
     57 10  
     58 1 2 3 4 5
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 10
     65 ```
     66 
     67 Note
     68 
     69 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.
     70 
     71 In the second example the possible strategy is to move ![](https://espresso.codeforces.com/e1e06f6a15cce30628c7a2360c4ffa57a8ba0ebd.png) in 4 moves, then ![](https://espresso.codeforces.com/c84dfbe0c6a917b45fc3f69467c256c4ac460eeb.png) in 3 moves, ![](https://espresso.codeforces.com/598731d81393332209d914cb0bbe97d8566c887d.png) in 2 moves and ![](https://espresso.codeforces.com/29f71c065c3536e88b54429c734103ad3604f68b.png) in 1 move.