Grabbing Land
Time limit1sMemory limit128 MB
Split N rectangles into groups, each group costing the product of its max width and max height, minimizing the total cost.
- Level
Hard8 of 10
- Topics
- Sorting, Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
Farmer Sangheon wants to buy all plots of land from Seonjae's real estate. Each plot is a rectangle with width and height .
Normally a single plot costs , but business has been slow, so Seonjae now offers the following bundle discount:
- When several plots are bought together as one bundle, the price of that bundle is (the maximum among the plots in the bundle) (the maximum among the plots in the bundle).
Sangheon will split the plots into one or more bundles and buy them all; every plot must belong to exactly one bundle. Because the total price depends on how the plots are grouped, find the minimum total cost to buy all of the plots.
Input
The first line contains the number of plots . ()
Each of the next lines contains the width and height of a plot, separated by a space. ()
Output
Print the minimum total cost to buy all of the plots on a single line.
Hint
For example, with the four plots , , , and , you can split them into the three bundles , , and . The cost is then .