求助,玄关
查看原帖
求助,玄关
1048193
PengDave楼主2024/7/24 21:45
#include<iostream>
using namespace std;
long long h[100010],w[100010];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);	int n;
	while(cin>>n){
		if(n==0){
			break;
		}
		long long ans=0;
		int tot=0;
		for(int i=1;i<=n;i++){
			int tmp;
			cin>>tmp;
			int tw=1;
			while(tmp<=h[tot]&&tot){
				long long wi=w[tot];
				w[tot-1]+=wi;
				tw+=wi;
				ans=max(ans,wi*h[tot]);
				tot--;
			}
			tot++;
			h[tot]=tmp;
			w[tot]=tw;
		}
		while(tot){
			long long wi=w[tot];
			w[tot-1]+=wi;
			ans=max(ans,wi*h[tot]);
			tot--;
		}
		cout<<ans<<"\n";
	}
	cout<<flush;
	return 0;
} 
2024/7/24 21:45
加载中...