萌新求助
查看原帖
萌新求助
217577
kemkra楼主2020/8/18 23:39
#include <cstdio>
#include <stack>
#include <algorithm>

using namespace std;

stack<long long> s;

int n, w;
long long h, ans;

int main() {
    while (scanf("%d", &n) && n) {
        for (int i = 0; i < n; i++) {
            scanf("%lld", &h);
            while (!s.empty() && h < s.top()) {
                ans = max(ans, s.top() * ++w);
                s.pop();
            }
            s.push(h);
            w = 0;
        }
        while (!s.empty()) {
            ans = max(ans, s.top() * ++w);
            s.pop();
        }
        printf("%d\n", ans);
    }
    return 0;
}
2020/8/18 23:39
加载中...