题意:
思路:
#include <cstdio>
#include <stack>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
int n,h[N],w[N],l[N],r[N];
void get(int a[N],bool f){
stack<int> s;
h[0] = -1;
s.push(0);
for(int i = 1;i <= n;i++){
while(s.size() && h[s.top()] >= h[i]) s.pop();
if(f) a[i] = s.top();
else a[n + 1 - i] = (n + 1 - s.top());
s.push(i);
}
}
int main(){
while(~scanf("%d",&n)){
if(n == 0) break;
for(int i = 1;i <= n;i++) scanf("%d",w+i),w[i] += w[i - 1];
for(int i = 1;i <= n;i++) scanf("%d",h + i);
get(l,1);
reverse(h + 1,h + 1 + n);
get(r,0);
ll res = 0;
for(int i = 1;i <= n;i++){
res = max(res , 1ll * h[n + 1 - i] * (w[r[i] - 1] - w[l[i]]) );
}
printf("%lld\n",res);
}
return 0;
}