-
Notifications
You must be signed in to change notification settings - Fork 0
/
L04-1.cpp
60 lines (47 loc) · 934 Bytes
/
L04-1.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
57
58
59
60
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
typedef long long ll;
#define PUB push_back
#define fi first
#define se second
int N;
ll light[100005], pjg[100005], ans = 0;
stack<ll> kanan, kiri;
int main(){
cin >> N;
for(int i=0;i<N;i++)
cin >> light[i];
//kanan -> kiri
for(int i=0;i<N;i++){
while(!kanan.empty() && light[kanan.top()] > light[i]){
int ind = kanan.top();
kanan.pop();
pjg[ind] = (i-ind);
}
kanan.push(i);
}
while(!kanan.empty()){
int ind = kanan.top();
kanan.pop();
pjg[ind] = N-ind;
}
//kiri -> kanan
for(int i=N-1;i>=0;i--){
while(!kiri.empty() && light[kiri.top()] > light[i]){
int ind = kiri.top();
kiri.pop();
pjg[ind] += (ind-i);
}
kiri.push(i);
}
while(!kiri.empty()){
int ind = kiri.top();
kiri.pop();
pjg[ind] += ind+1;
}
for(int i=0;i<N;i++){
ans = max(ans, (pjg[i]-1)*light[i]);
}
cout << ans << endl;
}