7060.Coin Arrangement

Time Limit: 1s Memory Limit: 512MB

There is a $2 \times n$ grid whose each cell contains some number of coins. The total number of coins is $2n$ .

Your task is to arrange the coins so that each cell contains exactly one coin. On each move you can choose any coin and move it one step left, right, up or down.

What is the minimum number of moves if you act optimally?

Input Format(From the terminal/stdin)

The first input line has an integer $n$ : the width of the grid.

After this, there are two lines that describe the grid. Each line has $n$ integers: the number of coins in each cell.

  • $1 \le n \le 10^5$

Output Format(To the terminal/stdout)

Print one integer: the minimum number of moves.

Sample Input

Copy
4
0 1 0 1
2 0 1 3
 \n
 · · · \n
 · · · \n

Sample Output

Copy
5
 \n
Source: CSES, Additional Problems II, 2180

Submit

请先 登录

© 2025 FAQs