-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvmss7wc15c2p3.cpp
More file actions
34 lines (33 loc) · 806 Bytes
/
Copy pathvmss7wc15c2p3.cpp
File metadata and controls
34 lines (33 loc) · 806 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
#include<bits/stdc++.h>
using namespace std;
int n,hill;
int main()
{
cin.sync_with_stdio(0); cin.tie(0);
cin>>n;
stack<pair<long long, long long>> hills;
long long counter=0;
for (int i=0;i<n;i++){
cin>>hill;
pair<long long, long long> p(hill,0);
while (!hills.empty()){
if (hills.top().first<p.first){
counter+=hills.top().second;
hills.pop();
}
else if (hills.top().first==p.first){
p.second = hills.top().second;
counter+=p.second;
hills.pop();
}
else{
counter++;
break;
}
}
p.second++;
hills.push(p);
}
cout<<counter<<endl;
return 0;
}