"Problem description"
Recently, Afy decided to give Toj print ads, billboards are painted in the city's buildings, the city has a close to the N buildings.
Afy decided to place a billboard on top of a rectangle as large as possible. We assume that each building has a height,
From left to right give the height of each building h1,h2 ... HN, and 0
Requires the maximum area of the output billboard.
"Input File"
The first line in the input file ad.in is a number n (n<= 400,000)
The second line is the number of N, which indicates the height of each building h1,h2 ... HN, and 0"Output File"
A total of one row in the output file Ad.out, representing the maximum area of the billboard.
"Input Sample"
6
5 8 4 4 8 4
"Output Example"
24
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring>using namespace STD; #define MAXN 400000 + 10int L[MAXN], r[maxn];int pos[maxn];int a[maxn];int n;void get_left () {int head = 1, tail = 0; for (int i = 1; I <= N, i++) {while (Head <= tail && a[pos[tail]] >= a[i]) tail--; L[i] = I-pos[tail]-1; Pos[++tail] = i; }}void get_right () {int head = 1, tail = 0; Pos[tail] = n + 1; for (int i = n, i >= 1; i--) {while (Head <= tail && a[pos[tail]] >= a[i]) tail--; R[i] = Pos[tail]-i-1; Pos[++tail] = i; }}int Main () {while (~SCANF ("%d", &n) {memset (l, 0, sizeof L); memset (r, 0, sizeof R); for (int i = 1; I <= n; i++) scanf ("%d", A + i); Get_left (); Get_right (); Long Long ans =-1; for (int i = 1; I <= n; i++) ans = max (ans, (long long) l[i] + r[i] + 1) * A[i]); printf ("%i64d\n", ans); } return 0;} /*65 8 4 4 8 4*/
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Monotone Queue Water Brush ads