Tranvick

Untitled

Nov 13th, 2011
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include <cstdio>
  6. #include <algorithm>
  7. #include <cmath>
  8. #include <vector>
  9. #include <set>
  10. #include <stack>
  11. #include <map>
  12. #include <queue>
  13. #include <string>
  14. #include <memory.h>
  15. #include <iterator>
  16. #define ll long long
  17. #define ull unsigned long long
  18. #define ul unsigned long
  19. #define ld long double
  20. #define mem(A,X) memset(A,X,sizeof(A))
  21. #define memo(A) memset(A,0,sizeof(A))
  22. #define forn(I,B) for (I=1;I<=(B);I++)
  23. #define repp(I,B) for (int I=0;I<(B);I++)
  24. #define fornn(I,B) for (int I=1;I<=(B);I++)
  25. #define rep(I,B) for (I=0;I<(B);I++)
  26. #define sz(X) ((int)(X.size()))
  27. #define lg(X) ((int)(X.length()))
  28. #define cl(X) (X).clear()
  29. #define labs(X) (((X)>0)?(X):(-(X)))
  30. #define INF 1111111111
  31. #define ropen(X) freopen(X,"r",stdin)
  32. #define wopen(X) freopen(X,"w",stdout)
  33. #define bg(X) (X.begin())
  34. #define en(X) (X.end())
  35. #define vi vector<int>
  36. #define pii pair<int,int>
  37. #define pll pair<long,long>
  38. #define pb push_back
  39. #define mp make_pair
  40. #define all(X) (X).begin(),(X).end()
  41. #define N
  42.                          
  43. using namespace std;      
  44.  
  45. priority_queue<ll> q1,q2;
  46.  
  47. int main(){
  48.    ios_base::sync_with_stdio(0);
  49. /*    ropen("d.in");
  50.    wopen("d.out");*/
  51.    ll x,i=2;
  52.    if (cin>>x)
  53.    cout<<x<<endl;  
  54.    else return 0;
  55.    q2.push(x);
  56.    while (cin>>x){
  57.        if ((sz(q2)-sz(q1)==0 || sz(q2)-sz(q1)==-1) && !q1.empty()) q2.push(x);
  58.        else q1.push(-x);
  59.        while (q2.top()>=-q1.top() && !q1.empty() && !q2.empty()){
  60.            q1.push(-q2.top());
  61.            q2.pop();
  62.        }
  63.        while (-q1.top()<=q2.top() && !q1.empty() && !q2.empty()){
  64.            q2.push(-q1.top());
  65.            q1.pop();
  66.        }
  67.        while (sz(q1)-sz(q2)>=1  && !q1.empty() && !q2.empty()){
  68.            q2.push(-q1.top());
  69.            q1.pop();
  70.        }
  71.        while (sz(q2)-sz(q1)>=1  && !q1.empty() && !q2.empty()){
  72.            q1.push(-q2.top());
  73.            q2.pop();
  74.        }
  75.        if ((sz(q1)+sz(q2))&1){
  76.            if (sz(q1)>sz(q2)) cout<<-q1.top();
  77.            else cout<<q2.top();
  78.            cout<<endl;
  79.        }else cout<<(q2.top()-q1.top())/2<<endl;
  80.  
  81.    }
  82.    return 0;
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment