We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5ddadd2 commit 1c35281Copy full SHA for 1c35281
CSES-Problem-Set/searching-sorting/learest-smaller-values.cpp
@@ -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