和poj2082差不多,加了一个宽度的条件
1 #include<cstdio> 2 #include<cmath> 3 #include<algorithm> 4 #include<cstring> 5 #include<iostream> 6 using namespace std; 7 const int MAXN=100005; 8 pair<int,int> ele[MAXN]; 9 int main(){ 10 int height, n; 11 int w; 12 int i,j,k,h; 13 int ans, tot, tmp; 14 int top=0; 15 while (scanf("%d", &n) != EOF && n!=-1) 16 { 17 top = 0; 18 ans = 0; 19 for(i=0;i<n;i++){ 20 tmp=0; 21 scanf("%d%d",&w,&h); 22 while(top>0&&h<ele[top-1].first){ 23 int aans=ele[top-1].first*(ele[top-1].second+tmp); 24 ans=max(ans,aans); 25 tmp+=ele[top-1].second; //这个比较容易忘,这是当前累计的加上之前累计的 26 top--; 27 } 28 ele[top].first=h; 29 ele[top].second=w+tmp; 30 top++; 31 } 32 tmp=0; 33 while(top>0){ 34 int aans=ele[top-1].first*(ele[top-1].second+tmp); 35 ans=max(ans,aans); 36 tmp+=ele[top-1].second; 37 top--; 38 } 39 printf("%d ", ans); 40 41 42 } 43 return 0; 44 45 }