AC代码:
[cpp]
/*此代码为 nyoj ac 代码,若在 hdu oj 要讲 long long 改为 __int64(对应输出格式也要改下),hdu oj 不支持 long long*/
#include
#include
#define max(a,b) a>b a:b
int stack[100010],len[100010];
int main()
{
int a,b,n,h;
while(scanf("%d",&n)&&n)
{
long long top=-1,ans=0;
for(a=0;a<=n;a++)
{
if(a
else
h=-1;
if(top<0||stack[top]
len[top]=1;
}
else
{
int l=0;
while(stack[top]>=h&&top>=0)
{
ans= max(ans,(long long)(len[top]+l)*stack[top]);
l+= len[top--];
}
if(h>0)
{
stack[++top]=h;
len[top]=1+l;
}
}
}
printf("%lld\n",ans);
}
}
作者:PIAOYI0208