2853.Group Photo 2 (online mirror version)

Time Limit: 1s Memory Limit: 256MB

Many years have passed, and n friends met at a party again. Technologies have leaped forward since the last meeting, cameras with timer appeared and now it is not obligatory for one of the friends to stand with a camera, and, thus, being absent on the photo.

Simply speaking, the process of photographing can be described as follows. Each friend occupies a rectangle of pixels on the photo: the i-th of them in a standing state occupies a wi pixels wide and a hi pixels high rectangle. But also, each person can lie down for the photo, and then he will occupy a hi pixels wide and a wi pixels high rectangle.

The total photo will have size W \times H, where W is the total width of all the people rectangles, and H is the maximum of the heights. The friends want to determine what minimum area the group photo can they obtain if no more than n/2 of them can lie on the ground (it would be strange if more than n/2 gentlemen lie on the ground together, isn't it?..)

Help them to achieve this goal.

Input Format(From the terminal/stdin)

The first line contains integer n (1 \le n \le 1000) - the number of friends.

The next n lines have two integers wi,hi (1 \le wi,hi \le 1000) each, representing the size of the rectangle, corresponding to the i-th friend.

Output Format(To the terminal/stdout)

Print a single integer equal to the minimum possible area of the photo containing all friends if no more than n/2 of them can lie on the ground.

Sample Input 1

Copy
3
10 1
20 2
30 3
 \n
  · \n
  · \n
  · \n

Sample Output 1

Copy
180
   \n

Sample Input 2

Copy
3
3 1
2 2
4 3
 \n
 · \n
 · \n
 · \n

Sample Output 2

Copy
21
  \n

Sample Input 3

Copy
1
5 10
 \n
 ·  \n

Sample Output 3

Copy
50
  \n

Submit

请先 登录

© 2025 FAQs