201312-3 最大的矩形
双指针/子序列
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 1010;
int n;
int h[MAXN];
int main() { // O(n^2)
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &h[i]);
int max_s = 0;
for (int i = 1; i <= n; ++i) {
int l = i, r = i; // 从i往两边数
while (l >= 1 && h[l] >= h[i]) l--;
while (r <= n && h[r] >= h[i]) r++;
int s = h[i] * (r - l - 1);
max_s = max(max_s, s);
}
printf("%d", max_s);
return 0;
}