单调栈+前缀和
单调栈维护区间的长度,然后用前缀和来计算最大值
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
typedef long long ll;
ll a[maxn],h[maxn];
int main()
{
ll n,ans=0;
cin>>n;
for(int i=1; i<=n; i++)
{
cin>>a[i];
a[i]+=a[i-1];
}
for(int i=1; i<=n; i++)
cin>>h[i];
stack <int> s;
s.push(0);
for(int i=1; i<=n; i++)
{
while(h[i]<h[s.top()])
{
int t1=s.top();
s.pop();
int t2=s.top();
ans=max(ans,h[t1]*(a[i-1]-a[t2]));
}
s.push(i);
}
cout<<ans<<endl;
}
京公网安备 11010502036488号