#P2900. [USACO08MAR] Land Acquisition G
[USACO08MAR] Land Acquisition G
Description
Farmer John is planning to expand his farm and is considering buying rectangular plots.
If FJ buys a single plot, the price equals the area of the plot. But he can choose to acquire a group of plots together, where the price of the group is the maximum length times the maximum width among those plots. For example, if FJ acquires a plot and a plot together, he only pays , which is cheaper than buying them separately.
FJ wants to buy all the plots. He found that partitioning the plots into different groups can save money. Given the dimensions of each plot, please help him compute the minimum total cost to purchase all plots.
Input Format
The first line contains an integer ().
Each of the next lines contains two integers and , denoting the length and the width of the -th plot. It is guaranteed that both the length and the width do not exceed .
Output Format
Output the minimum cost to buy all the plots.
4
100 1
15 15
20 5
1 100
500
Hint
Divide all plots into three groups:
- The first plot is in the first group, costing .
- The second and third plots are in the second group, costing .
- The fourth plot is in the third group, costing .
The total cost is , and it can be proven that no better plan exists.
Translated by ChatGPT 5
京公网安备 11011102002149号