Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n, t[1003];
- int st[1003];
- int main()
- {
- int i,x,k,top;
- k=top=0;
- cin>>n;
- for(i=1;i<=n;i++)
- cin>>t[i];
- st[++top]=1;
- for(i=2;i<=n;i++)
- {
- if(t[i]<=t[st[top]]) st[++top]=i;
- else
- {
- while(t[i]>t[st[top]] && top)
- top--;
- st[++top]=i;
- }
- }
- cout<<top<<"\n";
- for(i=1;i<=top;i++)
- cout<<st[i]<<" ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement