Advertisement
gabrielcabezas

Untitled

Mar 26th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. set <int> lf,rt;
  4. void adjust() {
  5. if (lf.size()> rt.size()+1)
  6. {
  7. rt.insert(*lf.rbegin());
  8. lf.erase(*lf.rbegin());
  9. }
  10. else if (lf.size()< rt.size())
  11. {
  12. lf.insert(*rt.begin());
  13. rt.erase(*rt.begin());
  14. }
  15. }
  16. void add (int x)
  17. {
  18. if (x>*rt.begin())
  19. rt.insert(x);
  20. else
  21. lf.insert(x);
  22. }
  23. int main()
  24. {
  25. int t,a;
  26. scanf("%d",&t);
  27. while (t--)
  28. {
  29. lf.clear();
  30. rt.clear();
  31. while (1)
  32. {
  33. scanf("%d",&a);
  34. if (a==0)break;
  35. else if (a!=-1)
  36. {
  37. add (a);
  38. adjust();
  39. }
  40. else if (a==-1)
  41. {
  42. printf("%d\n",*lf.rbegin());
  43. lf.erase(*lf.rbegin());
  44. adjust();
  45. }
  46. }
  47. }
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement