Advertisement
a53

Heap

a53
Jan 19th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <cstdio>
  2. #include <set>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n,t,x;
  8. freopen("heap.in","r",stdin);
  9. freopen("heap.out","w",stdout);
  10. multiset <int> my_set;
  11. scanf("%d",&n);
  12. for(int i=1;i<=n;++i)
  13. {
  14. scanf("%d",&t);
  15. if(t==1)
  16. {
  17. scanf("%d",&x);
  18. my_set.insert(x); /// Insereaza o valoare
  19. }
  20. if(t==2)
  21. { /// Valoarea maxima.
  22. multiset <int> :: iterator it = my_set.begin();
  23. it=my_set.end();
  24. --it;
  25. printf("%d\n", *it);
  26. /// Sterge o valoare din set. Daca aceasta se afla de
  27. /// mai multe ori in set, este stearsa numai o copie.
  28. my_set.erase(my_set.find(*it));
  29. }
  30. }
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement