Advertisement
Guest User

cub

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