Electronic Components
InterviewTime limit4sMemory limit1024 MB
Given N component types with counts and placement times, find the minimum total time to place all components when two different types can be placed in one move.
Problem
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 places one component at a time. A recent update lets it place two different components at the same time. The placement takes as long as the slower of the two components, so the bottleneck is the component with the greater placement time. It is not obvious what strategy minimizes the total placement time. Sara decides to write an algorithm to find that strategy.
There are different types of electronic components. There are copies of the th type, and each component of this type takes nanoseconds to place. The goal is to place all of the components using a sequence of moves. In one move, the machine can take two components of types and , where , and place both 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.
Input
The first line contains the integer ().
Each of the following lines contains two integers and (, ).
Output
Print one integer, the minimum time to place all components.