题目不看全就风风火火开始做的我也是醉了。。。。因为没看到n为0的时候结束,,改了好久都不知道错哪里。。。
一些题目明明自己做过了却忘了说明没有理解透,慢慢来复习。
#include <iostream>
#include <stdio.h>
using namespace std;
#define maxn 101000
#define ll long long
struct node
{
ll val,pos;
}que[maxn];
ll max(ll x,ll y){return x>y?x:y;}
int main()
{
ll n;
while(scanf("%lld",&n)!=EOF&&n)
{
ll x;
int top=0;
ll ans=0;
que[0].val=0,que[0].pos=0;
for(ll i=1;i<=n;i++)
{
scanf("%lld",&x);
if(i==1) {que[++top].val=x;que[top].pos=i;ans=x;continue;}
if(que[top].val<x)
{
que[++top].val=x;que[top].pos=i;
}
else
{
while(top>0&&que[top].val>=x)
{
ans=max(ans,(i-que[top-1].pos-1)*que[top].val);
top--;
}
ans=max(ans,(i-que[top].pos)*x);
que[++top].val=x;que[top].pos=i;
}
}
for(int i=1;i<=top;i++)
{
ans=max(ans,(que[top].pos-que[i-1].pos)*que[i].val);
}
printf("%lld\n",ans);
}
return 0;
}