Description
Farmer John prepares to expand his farm, and he is considering N (1 <= n <= 50,000) blocks of rectangular land. The length and width of each land is satisfied (1 <= wide <= 1,000,000; 1 <= long <= 1,000,000). The price of each piece of land is its area, but FJ can buy much faster land at the same time. The price of these lands is their largest length multiplied by their maximum width, but the length of the land cannot be exchanged. If FJ buys a 3x5 land and a 5x3, he needs to pay 5x5=25. FJ wanted to buy all the land, but he found that grouping to buy the land would save money. He needs you to help him find the minimum funds.
Input
* Line 1th: one number: N
* 2nd. N+1 Line: Line i+1 contains two numbers, respectively, the length and width of the land of Block I
Output
* First line: The minimum feasible cost.
Sample Input4
100 1
15 15
20 5
1 100
Input explanation:
There are 4 pieces of land.
Sample Output -
/*we can know that if xi<=xj&&yi<=yj, then x is useless. So we sort by x to get rid of the useless points so that the transfer equation becomes f[i]=f[j-1]+x[j]*y[i]. Consider two transfer f[j],f[k], and k<j<i; If transfer to f[i] from f[j] is better than from f[k], then f[j]+y[i]*x[j+1]<f[k]+y[i]*x[k+1]; The moving term is F (j), F (k+1)/x (k), × (j+1) <y (i) is then optimized with slope. */#include<cstdio>#include<iostream>#include<algorithm>#defineN 50010#defineLon Long Longusing namespaceStd;lon F[n];intN,m,q[n];structnode{intx, y;}; Node A[n],b[n];BOOLcmpConstNODE&S1,Constnode&S2) { returns1.x>s2.x| | (s1.x==s2.x&&s1.y>s2.y);}DoublexvintJintk) { return(F[j]-f[k])/(a[k+1].x-a[j+1].x);}intMain () {scanf ("%d",&N); for(intI=1; i<=n;i++) scanf ("%d%d",&b[i].x,&b[i].y); Sort (b+1, b+n+1, CMP); M=1; a[1]=b[1]; for(intI=2; i<=n;i++){ if(B[I].Y>A[M].Y) a[++m]=B[i]; } intHead=1, tail=1; q[1]=0; for(intI=1; i<=m;i++){ if(HEAD<TAIL&&XV (q[head],q[head+1]) <a[i].y) head++; F[i]=f[q[head]]+ (Lon) a[q[head]+1].x*(Lon) A[I].Y; while(HEAD<TAIL&&XV (q[tail-1],q[tail]) >XV (q[tail],i)) tail--; q[++tail]=i; } cout<<F[m]; return 0;}
Land purchase (Bzoj 1597)