一直在wa,但是不知道为什么,能找到的hack数据都过了
#include <bits/stdc++.h>
using namespace std;
int n;
int h[100010];
long long ans;
int main() {
freopen(".in", "r", stdin);
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";
}
}