Hamiltonian Circuit
시간 제한1초메모리 제한2048 MB
n개의 쌍 (a_i, b_i)가 주어질 때, 간선 i에서 j의 가중치가 |a_i - b_j|인 완전 유향 그래프에서 해밀턴 회로의 최대 가중치 합을 구한다.
문제
You are given pairs of integers .
Consider a weighted directed complete graph with vertices, where the weight of the edge from () to () is .
Find a Hamiltonian circuit in such that the sum of weights of the edges it traverses is maximized, and output this maximum value.
입력
The first line of the input contains an integer () representing the number of pairs.
Each of the next lines contains two integers and () representing a single pair.
You may assume that all integers and are pairwise distinct.
출력
Print a line with a single integer: the maximum sum of weights of the Hamiltonian circuit.
힌트
In the example, consider the Hamiltonian circuit , with edge weights . It can be proven that there is no Hamiltonian circuit with sum of weights exceeding , so the answer is .