nicuvlad76

Untitled

Dec 4th, 2020
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. struct cub{int poz, lung;}st[5000];
  6. int top=0;
  7.  
  8. int main()
  9. {
  10.     int n,x;
  11.     cin>>n;
  12.     for(int i=1;i<=n;i++)
  13.     {
  14.        cin>>x;
  15.         if(top==0 || x<=st[top].lung)///adaugare
  16.         {
  17.             st[++top].lung=x;
  18.             st[top].poz=i;
  19.         }
  20.         else///stergere
  21.         {
  22.            while(st[top].lung<x && top>0)
  23.                top--;
  24.            ///adaugare
  25.            st[++top].lung=x;
  26.             st[top].poz=i;
  27.         }
  28.     }
  29.     cout<<top<<'\n';
  30.     for(int i=1;i<=top;i++)cout<<st[i].poz<<' ';
  31.     return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment