感觉没错,玄关求调
查看原帖
感觉没错,玄关求调
930277
Benty楼主2025/7/22 19:03
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 1e5 + 10;

int n, top, ans, a[N];
int nums[N], w[N];

signed main() {
	while (cin >> n && n) {
		ans = 0, top = 0;
		for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);
		a[n + 1] = 0;
		
		for (int i = 1; i <= n + 1; i ++) {
			if (a[i] > nums[top]) {
				nums[++ top] = a[i];
				w[top] = 1;
			}
			else {
				int d = 0;
				while (nums[top] > a[i]) {
					d += w[top];
					ans = max(ans, (int)d * nums[top]);
					top --;
				}
				nums[++ top] = a[i], w[top] = d + 1;
			}
		}
		
		printf("%d\n", ans);
	}
	
	return 0;
} 
2025/7/22 19:03
加载中...