Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- struct cub{int poz, lung;}st[5000];
- int top=0;
- int main()
- {
- int n,x;
- cin>>n;
- for(int i=1;i<=n;i++)
- {
- cin>>x;
- if(top==0 || x<=st[top].lung)///adaugare
- {
- st[++top].lung=x;
- st[top].poz=i;
- }
- else///stergere
- {
- while(st[top].lung<x && top>0)
- top--;
- ///adaugare
- st[++top].lung=x;
- st[top].poz=i;
- }
- }
- cout<<top<<'\n';
- for(int i=1;i<=top;i++)cout<<st[i].poz<<' ';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment