TopCoder problem "TheSimpleGame" used in SRM 423 (Division II Level One)



Problem Statement

    

You have a n x n board and several checkers placed on it. The i-th checker is in the cell at row x[i], column y[i]. All coordinates are 1-based. There can be more than one checker in the same cell. A move consists of taking one checker and moving it one cell up, down, left or right.

You want to put each checker in one of the four corners of the board. Return the minimum number of moves necessary to achieve the goal.

 

Definition

    
Class:TheSimpleGame
Method:count
Parameters:int, int[], int[]
Returns:int
Method signature:int count(int n, int[] x, int[] y)
(be sure your method is public)
    
 

Constraints

-n will be between 1 and 100, inclusive.
-x will contain between 1 and 50 elements, inclusive.
-y will contain the same number of elements as x.
-Each element of x will be between 1 and n, inclusive.
-Each element of y will be between 1 and n, inclusive.
 

Examples

0)
    
4
{2}
{3}
Returns: 2
You need two moves to put the only checker to cell (1, 4).
1)
    
3
{2, 2, 1, 3}
{2, 2, 3, 1}
Returns: 4
For the first two checkers you can choose any of the four corners.
2)
    
7
{7, 1, 7, 7, 1, 7, 1}
{7, 1, 1, 1, 1, 7, 7}
Returns: 0
All checkers are already in the corners.

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=9966

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13514&pm=9966

Writer:

Vasyl[alphacom]

Testers:

PabloGilberto , bmerry , Olexiy , ivan_metelsky

Problem categories:

Simple Math