ACQUIRE - Land Acquisition

Gold Problem Land Acquisition [Paul Christiano, 2007]

Farmer John is considering buying more land for the farm and has his eye on N (1 <= N <= 50,000) additional rectangular plots, each with integer dimensions (1 <= width_i <= 1,000,000; 1 <= length_i <= 1,000,000).

If FJ wants to buy a single piece of land, the cost is $1/square unit, but savings are available for large purchases. He can buy any number of plots of land for a price in dollars that is the width of the widest plot times the length of the longest plot. Of course, land plots cannot be rotated, i.e., if Farmer John buys a 3x5 plot and a 5x3 plot in a group, he will pay 5x5=25.

FJ wants to grow his farm as much as possible and desires all the plots of land. Being both clever and frugal, it dawns on him that he can purchase the land in successive groups, cleverly minimizing the total cost by grouping various plots that have advantageous width or length values.

Given the number of plots for sale and the dimensions of each, determine the minimum amount for which Farmer John can purchase all

Input

  • Line 1: A single integer: N
  • Lines 2..N+1: Line i+1 describes plot i with two space-separated integers: width_i and length_i

Output

  • Line 1: The minimum amount necessary to buy all the plots.

Sample

Input:
4
100 1
15 15
20 5
1 100

Output:
500

Explanation

There are four plots for sale with dimensions as shown.

The first group contains a 100x1 plot and costs 100. The next group contains a 1x100 plot and costs 100. The last group contains both the 20x5 plot and the 15x15 plot and costs 300. The total cost is 500, which is minimal.


Added by:Hasan Jaddouh
Date:2013-05-31
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:USACO Mar08

hide comments
2016-08-02 11:18:31
will O(n^2) DP be good enough?
RE: Nice! Convex hull trick...

Last edit: 2016-08-02 16:12:31
2016-06-09 17:13:23
Taking long long int and still saying compilation error..
Re: Now WA... Works fine for every test case I check.

Last edit: 2016-06-09 17:22:37
2016-06-05 11:45:05
test cases are wrong...the correct solution would never be accepted. I say this because the test cases used in the actual USACO Mar08 ACQUIRE can be found here (http://train.usaco.org/TESTDATA/acquire.zip). My program passed all of them but is still WA here.

=(Francky)=> Or the USACO test cases are weak...

Last edit: 2016-06-05 12:51:56
2016-02-28 11:07:02
WA? nothing could be wrong in my code. Can someone tell me the critical test cases for this problem please..
2014-10-10 23:55:42 Tomek Weso³owski
6
100 1
90 2
50 50
40 60
10 100
5 200

OUTPUT: 5200
2013-06-26 06:23:46 nitish rao
getting WA... :( can anyone provide some corner test cases plzz... :)

RE: no tricky cases in this problem

Last edit: 2013-07-01 16:51:01
2013-06-07 16:39:54 RAJDEEP GUPTA
Should each group contain consecutive plots? Or can they contain plots that are not consecutive? In the example, each group contains consecutive plots for example. (1) (2,3) (4)

RE: no

Last edit: 2013-06-12 21:13:18
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.