Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int st[1001], sti[1001];
  5. bool v[1001];
  6. int main()
  7. {
  8. int vf=-1;
  9. int n, x;
  10. cin>>n;
  11. for(int i=1;i<=n;i++)
  12. {
  13. cin>>x;
  14. if(vf==-1)
  15. {
  16. st[++vf]=x;
  17. sti[vf]=i;
  18. }
  19. else
  20. if(x<=st[vf])
  21. {
  22. st[++vf]=x;
  23. sti[vf]=i;
  24. }
  25. else
  26. {
  27. while(x>st[vf] && vf!=-1)
  28. {
  29. vf--;
  30. }
  31. st[++vf]=x;
  32. sti[vf]=i;
  33. }
  34. //cout<<sti[vf]<<" ";
  35. }
  36. int k=0;
  37. while(vf!=-1)
  38. {
  39. v[sti[vf]]=1;
  40. vf--;
  41. k++;
  42. }
  43. cout<<k<<'\n';
  44. for(int i=1;i<=1000;i++)
  45. {
  46. if(v[i]==1)
  47. {
  48. cout<<i<<" ";
  49. }
  50. }
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement