Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int st[1001], sti[1001];
- bool v[1001];
- int main()
- {
- int vf=-1;
- int n, x;
- cin>>n;
- for(int i=1;i<=n;i++)
- {
- cin>>x;
- if(vf==-1)
- {
- st[++vf]=x;
- sti[vf]=i;
- }
- else
- if(x<=st[vf])
- {
- st[++vf]=x;
- sti[vf]=i;
- }
- else
- {
- while(x>st[vf] && vf!=-1)
- {
- vf--;
- }
- st[++vf]=x;
- sti[vf]=i;
- }
- //cout<<sti[vf]<<" ";
- }
- int k=0;
- while(vf!=-1)
- {
- v[sti[vf]]=1;
- vf--;
- k++;
- }
- cout<<k<<'\n';
- for(int i=1;i<=1000;i++)
- {
- if(v[i]==1)
- {
- cout<<i<<" ";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement