-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistogra.cpp
More file actions
49 lines (48 loc) · 827 Bytes
/
histogra.cpp
File metadata and controls
49 lines (48 loc) · 827 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
40
41
42
43
44
45
46
47
48
49
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pr pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
long cal(vector<long> &H,int n) {
int i=0;
long mA=0;
stack<int> s;
while(i<n) {
if(s.empty()||H[s.top()]<=H[i])
s.push(i++);
else {
int t=s.top();
s.pop();
long a=H[t]*(s.empty()?i:i-s.top()-1);
if(mA<a)
mA=a;
}
}
while(!s.empty()) {
int t=s.top();
s.pop();
long a=H[t]*(s.empty()?i:i-s.top()-1);
if(mA<a)
mA=a;
}
return mA;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
while(cin>>n) {
if(n==0)
break;
vector<long> H(n);
for(int i=0;i<n;i++)
cin>>H[i];
long ans=cal(H,n);
cout<<ans<<"\n";
}
return 0;
}