链接和说明
OJ链接:传送门
本题代码为LA姐
所作,笔者仅负责帮其调通代码。特此声明。
AC代码
cpp
#include<iostream>
#include<cmath>
using namespace std;
int main() {
int n;
scanf("%d", &n);//矩形个数
int *rec = (int *) malloc(n * sizeof(int));//矩形图
for (int i = 0; i < n; i++)
scanf("%d", &rec[i]);
int left, right;
int s = 0;//面积
int h;
for (int i = 0; i < n; i++)//遍历矩形图,找最大面积
{
left = right = i;
h = rec[i];
while (left - 1 >= 0 && rec[left - 1] >= h) {
left--;
}
while (right + 1 < n && rec[right + 1] >= h) {
right++;
}
s = max(s, h * (right - left + 1));
}
printf("%d", s);
free(rec);
return 0;
}