Max Pair Matching

시간 제한1초메모리 제한1024 MB

요약
2n개의 정수 쌍이 주어질 때, 각 간선의 가중치를 두 쌍의 경계 상자 사이의 체비쇼프 거리로 정의하고 완전 매칭의 최대 총 가중치를 구한다.
난이도

어려움10점 중 8점

유형
그리디, 정렬, 수학, 구현
정답자
아직 제출이 없습니다

문제

You are given 2n2n pairs (a_i,b_i)(a\_i, b\_i) of integers. Consider a complete graph on 2n2n vertices and define the weight of the edge (ij)(ij) to be w_ij=max(∣a_i−a_j∣,∣a_i−b_j∣,∣b_i−a_j∣,∣b_i−b_j∣)w\_{ij} = max(|a\_i-a\_j|, |a\_i-b\_j|, |b\_i-a\_j|, |b\_i-b\_j|).

Determine the maximum weight of the matching in this graph.

In other words, consider all ways to select nn edges of this graph such that no two chosen edges have a common endpoint. What is the maximum possible total weight of these edges?

입력

The first line of the input contains a single integer nn (1≤n≤1051 \le n \le 10^5).

The ii-th of the next 2n2n lines contain two integers a_ia\_i and b_ib\_i (0≤a_i,b_i≤1090 \le a\_i, b\_i \le 10^9).

출력

Print a single integer --- the maximum weight of the matching in this graph.

힌트

Adjacency matrix: 07915 7038 93011 158110\begin{matrix}0 & 7 & 9 & 15 \\\ 7 & 0 & 3 & 8 \\\ 9 & 3 & 0 & 11 \\\ 15 & 8 & 11 & 0 \end{matrix}

예제1

  1. 예제 1

    입력
    2
    0 10
    7 7
    9 4
    2 15
    
    예상 출력
    18