Problem description
n adjacent rectangles are placed on the horizontal axis, the width of each rectangle is 1, and the height of the first (1≤i≤n) rectangle is hi. These n rectangles form a histogram. For example, the height of the six rectangles is 3, 1, 6, 5, 2, 3, respectively.
Find the rectangle with the largest area in the given histogram, and its edges are parallel to the axis. For the example given above, the maximum rectangle as shown in the shaded portion, the area is 10.
Input format
The first line contains an integer n, which is the number of rectangles (1≤n≤1000).
The second line contains n integers h1, h2, ..., HN, and the adjacent numbers are separated by a space. (1≤hi≤10000). Hi is the height of the first rectangle.
The output format outputs a row that contains an integer that is the area of the largest rectangle within a given histogram. Sample input
6
3 1 6 5 2 3
Sample Output 10
#include <iostream> #include <vector> #include <algorithm>using namespace Std;int main () {int n,sum=0; cin>>n;vector<int>a;for (int i=0;i<n;i++) {int x;cin>>x;a.push_back (x);} for (int j=2;j<=n;j++) for (int k=0;k<n-(j-1); k++) {vector<int> b;int h=0,m=k;while (h<j) {B.push_back (a[ M]); h++;m++;} int min0=*min_element (B.begin (), B.end ()); int sum0=min0*j;if (sum0>sum) SUM=SUM0;} Cout<<sum<<endl;return 0;}
The largest rectangle (test all right, why only 20 points??) )