# bzoj1597 [Usaco2008 Mar]土地购买

## Input

* 第1行: 一个数: N

* 第2..N+1行: 第i+1行包含两个数,分别为第i块土地的长和宽

* 第一行: 最小的可行费用.

4
100 1
15 15
20 5
1 100

500

## HINT

FJ分3组买这些土地: 第一组:100x1, 第二组1x100, 第三组20x5 和 15x15 plot. 每组的价格分别为100,100,300, 总共500.

 1 //It is made by wfj_2048~
2 #include <algorithm>
3 #include <iostream>
4 #include <complex>
5 #include <cstring>
6 #include <cstdlib>
7 #include <cstdio>
8 #include <vector>
9 #include <cmath>
10 #include <queue>
11 #include <stack>
12 #include <map>
13 #include <set>
14 #define inf (1<<30)
15 #define il inline
16 #define RG register
17 #define ll long long
18 #define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
19
20 using namespace std;
21
22 struct node{ ll a,b; }p[50010],s[50010];
23
24 ll f[50010],q[50010],n,cnt,st,ed;
25
26 il ll gi(){
27     RG ll x=0,q=1; RG char ch=getchar();
28     while ((ch<'0' || ch>'9') && ch!='-') ch=getchar();
29     if (ch=='-') q=-1,ch=getchar();
30     while (ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar();
31     return q*x;
32 }
33
34 il ll cmp(const node &x,const node &y){
35     if (x.a==y.a) return x.b<y.b; return x.a<y.a;
36 }
37
38 il double getk(RG ll i,RG ll j){
39     return 1.0*(f[i]-f[j])/(s[i+1].b-s[j+1].b);
40 }
41
42 il void work(){
43     n=gi(); for (RG ll i=1;i<=n;++i) p[i].a=gi(),p[i].b=gi();
44     sort(p+1,p+n+1,cmp);
45     for (RG ll i=1;i<=n;++i){
46     while (cnt && s[cnt].a<=p[i].a && s[cnt].b<=p[i].b) cnt--;
47     s[++cnt]=p[i];
48     }
49     s[cnt+1].b=1,st=ed=1;
50     for (RG ll i=1;i<=cnt;++i){
51     while (st<ed && getk(q[st],q[st+1])>=-s[i].a) st++;
52     f[i]=f[q[st]]+s[i].a*s[q[st]+1].b;
53     while (st<ed && getk(q[ed],q[ed-1])<=getk(q[ed],i)) ed--;
54     q[++ed]=i;
55     }
56     printf("%lld\n",f[cnt]); return;
57 }
58
59 int main(){
63 }