-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhdu1506.cpp
More file actions
39 lines (36 loc) · 773 Bytes
/
hdu1506.cpp
File metadata and controls
39 lines (36 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <cstdio>
#include <cstring>
const int MAX_N = 100007;
int n;
long long h[MAX_N], l[MAX_N], r[MAX_N];
int main() {
while (1 == scanf("%d", &n)) {
if (0 == n)
break;
for (int i = 1; i <= n; ++i) {
scanf("%I64d", &h[i]);
}
for (int i = 1; i <= n; ++i) {
l[i] = i - 1;
r[i] = i + 1;
}
for (int i = 1; i <= n; ++i) {
while (h[l[i]] >= h[i] && l[i] > 0)
l[i] = l[l[i]];
}
for (int i = n; i >= 1; --i) {
while (h[r[i]] >= h[i] && r[i] <= n)
r[i] = r[r[i]];
}
long long ans = 0;
for (int i = 1; i <= n; ++i) {
// printf("%d %d %d\n", i, l[i], r[i]);
if (h[i] * (r[i] - l[i] - 1) > ans) {
// printf("%d\n", i);
ans = h[i] * (r[i] - l[i] - 1);
}
}
printf("%I64d\n", ans);
}
return 0;
}