精度很重要,看到大数字就要注意是否要使用long long 或者是 __int64
#include"iostream"
#include"cstdio"
#include"algorithm"
#include"vector"
#include"string"
#include"stack"
using namespace std;
const int maxn=100000+10;
__int64 height[maxn];
stack<int>Stack;
int n;
__int64 solution()
{
__int64 Max=0;
for(int i=0;i<=n;i++)
{
__int64 high=(i==n?0:height[i]);
if(Stack.empty()||high>=height[Stack.top()])
Stack.push(i);
else
{
int tp=Stack.top();
Stack.pop();
Max=max(Max,__int64(height[tp]*(Stack.empty()?i:i-Stack.top()-1)));
i--;
}
}
return Max;
}
int main()
{
//freopen("a.txt","r",stdin);
while(scanf("%d",&n),n)
{
while(!Stack.empty())
Stack.pop();
for(int i=0;i<n;i++)
scanf("%I64d",height+i);
printf("%I64d\n",solution());
}
return 0;
}