#include<cstdio>
#define MAX_N 50050
#define MAX(x,y) ((x)>(y)?(x):(y))
using namespace std;
int stack[MAX_N],l[MAX_N],r[MAX_N],d[MAX_N],w[MAX_N];
int n;
int cal()
{
int tot=0;
for(int i=0;i<n;i++)
{
while(tot>0&&d[stack[tot-1]]>=d[i])
tot--;
l[i]=tot==0?0:(stack[tot-1]+1);
stack[tot++]=i;
}
tot=0;
for(int i=n-1;i>=0;i--)
{
while(tot>0&&d[stack[tot-1]]>=d[i])
tot--;
r[i]=tot==0?n:stack[tot-1];
stack[tot++]=i;
}
long long res=0;
for(int i=0;i<n;i++)
res=MAX(res,d[i]*(w[r[i]]-w[l[i]]));
return res;
}
int main()
{
while(~scanf("%d",&n)&&(n!=-1))
{
int temp;
w[0]=0;
for(int i=0;i<n;i++)
{
scanf("%d%d",&temp,&d[i]);
w[i+1]=w[i]+temp;
}
printf("%d\n",cal());
}
}
poj 2082 Terrible Sets(单调栈)
最新推荐文章于 2020-02-03 20:58:37 发布