아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Tree Construction

시간 제한2초메모리 제한512 MB

요약
x가 커지면 y가 작아지는 순서로 주어진 점들을 오른쪽이나 위쪽 방향 간선으로 모두 연결할 때, 간선 길이 합의 최솟값을 구한다.
난이도

보통10점 중 6점

유형
최소 신장 트리, 기하, 정렬
정답자
아직 제출이 없습니다

문제

Consider a two-dimensional space with a set of points (xi, yi) that satisfy xi < xj and yi > yj for all i < j. We want to have them all connected by a directed tree whose edges go toward either right (x positive) or upward (y positive). The figure below shows an example tree.

Figure 1: An example tree

Write a program that finds a tree connecting all given points with the shortest total length of edges.

입력

The input begins with a line that contains an integer n (1 ≤ n ≤ 1000), the number of points. Then n lines follow. The i-th line contains two integers xi and yi (0 ≤ xi, yi ≤ 10000), which give the coordinates of the i-th point.

출력

Print the total length of edges in a line.

예제2

  1. 예제 1

    입력
    5
    1 5
    2 4
    3 3
    4 2
    5 1
    
    예상 출력
    12
    
  2. 예제 2

    입력
    1
    10000 0
    
    예상 출력
    0