显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
struct statype
{
int bhei,bpos,ahei,apos;
}sta[100010];
int top=-1;
int main(void)
{
freopen("tahort.in","r",stdin);
freopen("tahort.out","w",stdout);
int i,n,ans=0;
cin>>n;
for (i=1;i<=n;i++)
{
top++;
cin>>sta[top].bhei;
sta[top].ahei=sta[top].bhei;
sta[top].bpos=i;
sta[top].apos=i;
while (sta[top].bhei>sta[top-1].bhei&&top>=1)
{
if (sta[top].ahei>sta[top-1].ahei)
{
sta[top].ahei=sta[top-1].ahei;
sta[top].apos=sta[top-1].apos;
}
sta[top-1]=sta[top];
sta[top].bhei=0;
sta[top].bpos=0;
sta[top].apos=0;
top--;
}
if (ans<sta[top].bpos-sta[top].apos+1)
ans=sta[top].bpos-sta[top].apos+1;
}
if (ans==1)
ans=0;
cout<<ans<<endl;
return(0);
}