Electronic Components
시간 제한4초메모리 제한1024 MB
배치 시간 t_i인 부품 종류별로 f_i개씩 있을 때, 서로 다른 종류를 짝지어 배치하는 데 걸리는 최소 총시간을 구한다.
문제
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 different types of electronic components. There are copies of the th type, and the components of this type have a placement time of 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 and , where , and place both of them simultaneously. This takes nanoseconds. The machine can also place a single component of type in one move, which takes nanoseconds.
Calculate the minimum possible time to place all components.
입력
The first line of input contains the integer ().
The following lines each contain two integers and (, ).
출력
Print one integer, the minimum time to place all components.