#include<iostream>
#include<stack>
#include<cstdio>
using namespace std;
const int N=int (1e5)+9;
int h[N]; // high
int n;
int main()
{
// freopen("in.txt","r",stdin);
// freopen("in_out.txt","w",stdout);
while(cin>>n && n){
for(int i=1;i<=n;++i){
scanf("%d",&h[i]);
}
long long ans=0;
stack<int> S; S.push(0);
h[++n]=0;
// stack
for(int i=1;i<=n;++i){
while(h[i]<h[S.top()]){
long long a=h[S.top()];
S.pop();
long long b=i-S.top()-1;
if(a*b>ans){
ans= a*b;
}
}
S.push(i);
}
printf("%lld\n",ans);
}
}
poj:Largest Rectangle in a Histogram
最新推荐文章于 2022-01-16 20:26:37 发布
