import java.util.*;
public class joi2019_ho_t4 {
static class Point {
long x, y;
Point(long x, long y) {
this.x = x;
this.y = y;
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
Point[] coins = new Point[2 * N];
Point[] targets = new Point[2 * N];
for (int i = 0; i < 2 * N; i++) {
long x = scanner.nextLong();
long y = scanner.nextLong();
coins[i] = new Point(x, y);
}
for (int i = 0; i < N; i++) {
targets[2 * i] = new Point(i + 1, 1);
targets[2 * i + 1] = new Point(i + 1, 2);
}
Arrays.sort(coins, Comparator.comparingLong(p -> p.x));
Arrays.sort(targets, Comparator.comparingLong(p -> p.x));
long totalDistance = 0;
for (int i = 0; i < 2 * N; i++) {
totalDistance += Math.abs(coins[i].x - targets[i].x) + Math.abs(coins[i].y - targets[i].y);
}
System.out.println(totalDistance);
scanner.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... |