Skip to content

Commit 1c35281

Browse files
left smallest value
1 parent 5ddadd2 commit 1c35281

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// link : https://cses.fi/problemset/task/1645/
2+
3+
#include<bits/stdc++.h>
4+
#define ll long long int
5+
using namespace std;
6+
#define MOD 1000000007
7+
int sumd(int _a){int res=0;while(_a){res=res+(_a%10);_a=_a/10;}return res;}
8+
int main() {
9+
ios_base::sync_with_stdio(0);
10+
cin.tie(0);
11+
int n;
12+
cin>>n;
13+
vector<int>arr(n);
14+
for(auto &it:arr){
15+
cin>>it;
16+
}
17+
stack<int>st;
18+
for(int i=0;i<n;i++){
19+
while(!st.empty() and arr[st.top()]>=arr[i]){
20+
st.pop();
21+
}
22+
if(st.empty()){
23+
cout<<0<<" ";
24+
}
25+
else{
26+
cout<<st.top()+1<<" ";
27+
}
28+
st.push(i);
29+
}
30+
cout<<endl;
31+
return 0;
32+
}

0 commit comments

Comments
 (0)