Advertisement
gabrielcabezas

Untitled

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