import java.util.*;
public class joi2019_ho_t4 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int total = 2 * N;
long[] xs = new long[total];
long[] ys = new long[total];
for (int i = 0; i < total; i++){
xs[i] = sc.nextLong();
ys[i] = sc.nextLong();
}
Arrays.sort(xs);
long costX = 0;
for (int i = 0; i < total; i++){
long target = (i / 2) + 1;
costX += Math.abs(xs[i] - target);
}
Arrays.sort(ys);
long baseY = 0;
int countMinus = 0;
for (int i = 0; i < total; i++){
if(ys[i] <= 1){
baseY += (2 - ys[i]);
countMinus++;
} else {
baseY += (ys[i] - 2);
}
}
long extra = (countMinus >= N) ? -N : (N - 2L * countMinus);
long costY = baseY + extra;
System.out.println(costX + costY);
sc.close();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |