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 ≤ widthi ≤ 1,000,000; 1 ≤ lengthi ≤ 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 3×5 plot and a 5×3 plot in a group, he will pay 5×5 = 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: widthi and lengthi
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 100×1 plot and costs 100. The next group contains a 1×100 plot and costs 100. The last group contains both the 20×5 plot and the 15×15 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
|
||||||
2024-08-27 11:05:29
Tree of Li chao that's the way to solve this!!! Also DSU with erasion and Z-function to make from O(N) to O(-1) Last edit: 2024-08-27 11:06:03 |
||||||
2021-12-19 16:59:12
DP with Convex Hull Trick ! just remember to eliminate unnecessary plots |
||||||
2020-12-02 16:26:57
why do i get " runtime error (SIGSEGV) " ? anyone can show me some testcases? |
||||||
2020-05-18 21:42:24
its giving tle with O(n*n) solution in c++14 |
||||||
2020-05-10 15:19:30 Rishabh
O(n^2) not getting AC. Need to will convex hull trick |
||||||
2019-09-25 17:59:45
Why problem tags are always visible? There is no way to hide them? :/ This problem also should be solved. |
||||||
2019-09-24 22:00:26
This problem can be solved in O(n.log(n)) using Convex Hull or 1D/1D optimizations. But should not be solvable in O(n^2). The site admin should decrease the time complexity of this problem. Last edit: 2019-09-25 17:58:45 |
||||||
2019-09-24 21:57:24
For the sake of god, please do not write "in one go". |
||||||
2019-07-20 06:30:32
after removing irrelevant rectangles, O(n * n) solution passed |
||||||
2018-11-14 05:31:43
Bruteforce - > AC |