迷惑错误
查看原帖
迷惑错误
22716
神仙酱楼主2024/6/19 16:32

一直在wa,但是不知道为什么,能找到的hack数据都过了

#include <bits/stdc++.h>
using namespace std;
int n;
int h[100010];
long long ans;

int main() {
    freopen(".in", "r", stdin);
    // cin.tie(0)->sync_with_stdio(0);
    stack<pair<int, int>> s;
    while (cin >> n, n) {
        ans = 0;
        for (int i = 1; i <= n; i++)
            cin >> h[i];
        h[n + 1] = 0;
        for (int i = 1; i <= n + 1; i++) {
            int width = 0;
            while (!s.empty() && h[s.top().first] > h[i]) {
                width += s.top().second;
                ans = max(ans, (long long)width * h[s.top().first]);
                s.pop();
            }
            s.push({ i, width + 1 });
        }
        s.pop();
        cout << ans << "\n";
    }
}
2024/6/19 16:32
加载中...