Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int n, t[1003];
  6. int st[1003];
  7.  
  8. int main()
  9. {
  10. int i,x,k,top;
  11. k=top=0;
  12. cin>>n;
  13. for(i=1;i<=n;i++)
  14. cin>>t[i];
  15. st[++top]=1;
  16. for(i=2;i<=n;i++)
  17. {
  18. if(t[i]<=t[st[top]]) st[++top]=i;
  19. else
  20. {
  21. while(t[i]>t[st[top]] && top)
  22. top--;
  23. st[++top]=i;
  24. }
  25. }
  26. cout<<top<<"\n";
  27. for(i=1;i<=top;i++)
  28. cout<<st[i]<<" ";
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement