Submit | All submissions | Best solutions | Back to list |
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
|
||||||
2018-11-09 04:11:48
Getting TLE even after removing irrelevant rectangles and applying dp solution O(n^2). |
||||||
2018-09-11 16:19:29
AC in 1 go, test cases are correct. Check your code again and again until you find the bug. |
||||||
2018-06-03 13:14:31
WA!!! I followed the method given on Wiki, convex-hull-trick dp solution |
||||||
2018-04-11 19:40:03
OK friends if you are getting WA these are the test cases: http://contest.usaco.org/MAR08.htm. Hope that helps |
||||||
2018-03-07 14:55:47
I submitted the solution given in the wcipeg article and got WA. |
||||||
2018-02-03 01:45:00
Good convex hull trick! |
||||||
2017-07-30 21:29:22
Finally accepted!!o(n2) solution.useful link https://wcipeg.com/wiki/Convex_hull_trick for solving |
||||||
2017-06-21 10:44:47
Removed irrelevant rectangles and O(n^2) DP passed. |
||||||
2017-06-08 06:50:38
I tried both dp and convex hull technique, only latter gives AC (dp solution passes all test cases of spoj toolkit), dp solution gives WA. |
||||||
2016-09-15 13:12:24
I haven't read convex hull trick and am trying to pass a O(n^2) solution, but am getting WA. My code gives the correct answer for all test cases on spojtoolkit.com Kindly help me with a few peculiar test cases. |