传送门:https://vjudge.net/problem/17973/origin
解题分析:
#include<iostream>
#include<stack>
#define ll long long
using namespace std;
stack<int> h,l;
int n;
int main()
{
while(cin>>n&&n!=-1)
{
while(l.size()) l.pop();
while(h.size()) h.pop();
int ans=0,x,y,k;
for(int i=1;i<=n;i++)
{
cin>>x>>y;
k=0;
while(h.size()&&h.top()>=y)
{
k+=l.top();
ans=max(ans,k*h.top());
h.pop();
l.pop();
}
h.push(y);
l.push(k+x);
}
k=0;
while(h.size())
{
k+=l.top();l.pop();
ans=max(ans,k*h.top());
h.pop();
}
cout<<ans<<endl;
}
return 0;
}