題目描述
共n條木板緊密排列在一條直線上素跺,從左到右的第i條高度為h[i]二蓝,寬度為1。你希望在這些木條上找到一左一右兩個木條指厌,從左到右拉一個橫幅刊愚。當然橫幅的高度會是以這兩個木條中較矮的那個為準。請問橫幅的最大面積是多少踩验?
輸入輸出格式
輸入格式
輸入文件banner.in 輸入第一行為正整數(shù)n鸥诽,n<=100000,第二行為整數(shù)h[1],h[2],..,h[n], 均在0到10000之間晰甚。
輸出格式
輸出文件banner.out 輸出一個整數(shù)
樣例數(shù)據(jù)
輸入數(shù)據(jù)
3
2 1 3
輸出數(shù)據(jù)
6
標簽
普及/提高-
AC代碼
#include <bits/stdc++.h>
using namespace std;
int main(){
freopen("banner.in","r",stdin);
freopen("banner.out","w",stdout);
long long n,h[200000];
cin>>n;
for(long long i=1;i<=n;i++)cin>>h[i];
long long l=1,r=n,ans=0;
while(l<r){
long long hei=min(h[l],h[r]);
long long wdh=r-l+1;
long long area=hei*wdh;
ans=max(ans,area);
if(h[l]<h[r])l++;
else r--;
}
cout<<ans;
return 0;
}