Electronic Components

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

요약
배치 시간 t_i인 부품 종류별로 f_i개씩 있을 때, 서로 다른 종류를 짝지어 배치하는 데 걸리는 최소 총시간을 구한다.
난이도

보통10점 중 7점

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

문제

Sara is doing her summer internship at NCPC (Never Crashing Personal Computers). One day, a rare creature appeared in the office: an algorithmic problem!

The company has a machine that places electronic components on circuit boards. Normally, it would do this one component at a time. But recently the machine has received an update which allows it to place two different components simultaneously. The bottleneck then becomes the component with greater placement time. Now it is far from obvious what strategy the machine should use in order to minimize the total placement time. Sara decides to write an algorithm to determine this strategy.

You have NN different types of electronic components. There are f_if\_i copies of the iith type, and the components of this type have a placement time of t_it\_i nanoseconds. The goal is to place all of the components using a sequence of moves. In one move, the machine can take two components of type ii and jj, where i≠ji \neq j, and place both of them simultaneously. This takes max⁡(t_i,t_j)\max(t\_i, t\_j) nanoseconds. The machine can also place a single component of type ii in one move, which takes t_it\_i nanoseconds.

Calculate the minimum possible time to place all components.

입력

The first line of input contains the integer NN (1≤N≤10001 \leq N \leq 1000).

The following NN lines each contain two integers f_if\_i and t_it\_i (1≤f_i≤1041 \leq f\_i \leq 10^4, 1≤t_i≤1091 \leq t\_i \leq 10^9).

출력

Print one integer, the minimum time to place all components.

예제3

  1. 예제 1

    입력
    3
    2 7
    2 1
    3 10
    
    예상 출력
    31
    
  2. 예제 2

    입력
    3
    2 10
    2 11
    2 12
    
    예상 출력
    35
    
  3. 예제 3

    입력
    4
    2 11
    7 10
    3 5
    1 1
    
    예상 출력
    72