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

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

Relay

면접 대비

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

요약
서로 다른 세 명을 골라 순서를 정해 A_i + max(B_i,B_j) + A_j + max(B_j,B_k) + A_k의 최솟값을 구한다. N은 200,000까지 주어진다.
난이도

보통10점 중 7점

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

문제

There are NN members in the track club of JOI High School, numbered from 11 to NN. For the member ii (1≤i≤N1 ≤ i ≤ N), the time of the 100 m sprint is A_iA\_i msec, and the ability of controlling the baton is B_iB\_i.

The track club will participate in a national contest for the 300 m relay. Three members will run in the 300 m relay. Each member will run for 100 m. A runner will pass the baton to the next runner. Precisely, if the first runner is the member ii (1≤i≤N1 ≤ i ≤ N), the second runner is the member jj (1≤j≤N1 ≤ j ≤ N), and the third runner is the member kk (1≤k≤N1 ≤ k ≤ N), then the three members will run the relay in the following steps.

  1. The member ii runs for 100 m with a baton. It takes A_iA\_i msec.
  2. The member ii gives a baton to the member jj. It takes max⁡(B_i,B_j)\max{(B\_i , B\_j)} msec.
  3. The member jj runs for 100 m with a baton. It takes A_jA\_j msec.
  4. The member jj gives a baton to the member kk. It takes max⁡(B_j,B_k)\max{(B\_j , B\_k)} msec.
  5. The member kk runs for 100 m with a baton. It takes A_kA\_k msec.

Therefore, the record for the 300 m relay is A_i+max⁡(B_i,B_j)+A_j+max⁡(B_j,B_k)+A_kA\_i + \max{(B\_i , B\_j)} + A\_j + \max{(B\_j , B\_k)} + A\_k msec. Here max⁡(x,y)\max{(x, y)} is the largest value of xx and yy. Since you are the coach of the track club, you want to choose three distinct members for the relay and decide the order of the runners so that the record becomes minimum.

Write a program which, given information of the NN members of the track club, calculates the minimum possible record of the 300 m relay.

입력

Read the following data from the standard input. Given values are all integers.

NN

A_1A\_1 B_1B\_1

A_2A\_2 B_2B\_2

⋮\vdots

A_NA\_N B_NB\_N

출력

Write one line to the standard output. The output should contain an integer which is the minimum possible record of the 300 m relay counted by msec.

제한

  • 3≤N≤200,0003 ≤ N ≤ 200\\,000.
  • 1≤A_i≤100,000,000(=108)1 ≤ A\_i ≤ 100\\,000\\,000 (= 10^8) (1≤i≤N1 ≤ i ≤ N).
  • 1≤B_i≤100,000,000(=108)1 ≤ B\_i ≤ 100\\,000\\,000 (= 10^8) (1≤i≤N1 ≤ i ≤ N).

예제3

  1. 예제 1

    입력
    4
    1070 90
    1080 70
    1050 60
    1020 100
    
    예상 출력
    3320
    
  2. 예제 2

    입력
    5
    1000 28
    1000 14
    1000 21
    1000 20
    1000 14
    
    예상 출력
    3034
    
  3. 예제 3

    입력
    9
    3 1
    4 1
    5 9
    2 6
    5 3
    5 8
    9 7
    9 3
    2 3
    
    예상 출력
    13