-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1725.cpp
More file actions
41 lines (37 loc) · 773 Bytes
/
1725.cpp
File metadata and controls
41 lines (37 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
40
41
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
using namespace std;
const ll INF = 1e9 + 7;
const ll DIV = 987654321;
int n;
stack<pair<int,int>> st;
int main()
{
fastio;
cin >>n;
int ans=0;
st.push({-1, -1});
for(int i=0;i<n;i++){
int a;
cin >> a;
while(1){
auto[x,h] = st.top();
if(h < a){
break;
}
st.pop();
auto[y, z]=st.top();
ans=max(ans, (i-y-1)*h);
}
st.push({i,a});
}
while(st.size() > 1){
auto[x,h]=st.top();
st.pop();
auto[y, z]=st.top();
ans=max(ans, (n-y-1)*h);
}
cout << ans;
return 0;
}