#include<cstdio>
#define max(x,y) ((x)>(y)?(x):(y))
using namespace std;
int main()
{
int stack[100010],h[100010],L[100010],R[100010];
int n;
while(~scanf("%d",&n)&&n)
{
int i,t;
for(i=0;i<n;i++)
{
scanf("%d",&h[i]);
}
t=0;
for(i=0;i<n;i++)
{
while(t>0&&h[stack[t-1]]>=h[i])
t--;
L[i]=t==0?0:(stack[t-1]+1);
stack[t++]=i;
}
t=0;
for(i=n-1;i>=0;i--)
{
while(t>0&&h[stack[t-1]]>=h[i])
t--;
R[i]=t==0?n:stack[t-1];
stack[t++]=i;
}
long long res=0;
for(i=0;i<n;i++)
res=max(res,(long long)h[i]*(R[i]-L[i]));
printf("%lld\n",res);
}
}
poj 2559 栈的运用
最新推荐文章于 2020-08-23 19:22:16 发布