forked from mohitsh/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistogra.cpp
56 lines (56 loc) · 852 Bytes
/
histogra.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// 2008-07-28
#define _CRT_SECURE_NO_WARNINGS
#ifdef ONLINE_JUDGE
#define GC getchar_unlocked
#else
#define GC getchar
#endif
#include <iostream>
using namespace std;
int input()
{
int x=0;
char c;
for(;;)
{
c=GC();
if (c==' '||c=='\n'||c==-1)
return x;
x=10*x+c-'0';
}
}
int main()
{
static int I[100002];
static int h[100002];
static int l[100002];
static int r[100002];
int n,i,top;
for(;;)
{
n=input();
if (!n) return 0;
h[0]=-1;
h[n+1]=-1;
top=0;
for (i=1; i<=n; i++)
h[i]=input();
for (i=1; i<=n+1; i++)
{
while (top&&h[I[top-1]]>h[i])
r[I[--top]]=i;
I[top++]=i;
}
top=0;
for (i=n; i>=0; i--)
{
while (top&&h[I[top-1]]>h[i])
l[I[--top]]=i;
I[top++]=i;
}
long long best=0;
for (i=1; i<=n; i++)
best=max(best,(long long)h[i]*(r[i]-l[i]-1));
printf("%lld\n",best);
}
}