思路: 对每个柱子h,左右撑满就是就是这个高度对应的面积的极大值,取最大就可以了;
#include<algorithm> #include<cstdlib> #include<iostream> #include<cstring> #include<cstdlib> #include<queue> #include<functional> #include<utility>//pair #define INF 0x7f7f7f7f #define getrand(a,b) (int)((rand()/33000.0)*((b)-(a)+1))+(a) using namespace std; typedef long long LL; const int maxnn=100+5; const int maxn=100000+5; const int mod=1e9+7; priority_queue< pair<LL,int> > q; int main() { int n,x,m; LL ans=0; cin>>n; for(int i=0;i<n;i++){ cin>>x; m=1<<30; //左侧 while((!q.empty())&&q.top().first>x){ if(m>q.top().second) m=q.top().second; ans=max(ans,q.top().first*(i-q.top().second)); q.pop(); } if(m!=1<<30) q.push((pair<LL,int>){x,m}); else q.push((pair<LL,int>){x,i}); } while(!q.empty()){ ans=max(ans,q.top().first*(n-q.top().second)); q.pop(); } cout<<ans<<endl; return 0; }