Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- #include <ctime>
- #include <cstdio>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <set>
- #include <stack>
- #include <map>
- #include <queue>
- #include <string>
- #include <memory.h>
- #include <iterator>
- #define ll long long
- #define ull unsigned long long
- #define ul unsigned long
- #define ld long double
- #define mem(A,X) memset(A,X,sizeof(A))
- #define memo(A) memset(A,0,sizeof(A))
- #define forn(I,B) for (I=1;I<=(B);I++)
- #define repp(I,B) for (int I=0;I<(B);I++)
- #define fornn(I,B) for (int I=1;I<=(B);I++)
- #define rep(I,B) for (I=0;I<(B);I++)
- #define sz(X) ((int)(X.size()))
- #define lg(X) ((int)(X.length()))
- #define cl(X) (X).clear()
- #define labs(X) (((X)>0)?(X):(-(X)))
- #define INF 1111111111
- #define ropen(X) freopen(X,"r",stdin)
- #define wopen(X) freopen(X,"w",stdout)
- #define bg(X) (X.begin())
- #define en(X) (X.end())
- #define vi vector<int>
- #define pii pair<int,int>
- #define pll pair<long,long>
- #define pb push_back
- #define mp make_pair
- #define all(X) (X).begin(),(X).end()
- #define N
- using namespace std;
- priority_queue<ll> q1,q2;
- int main(){
- ios_base::sync_with_stdio(0);
- /* ropen("d.in");
- wopen("d.out");*/
- ll x,i=2;
- if (cin>>x)
- cout<<x<<endl;
- else return 0;
- q2.push(x);
- while (cin>>x){
- if ((sz(q2)-sz(q1)==0 || sz(q2)-sz(q1)==-1) && !q1.empty()) q2.push(x);
- else q1.push(-x);
- while (q2.top()>=-q1.top() && !q1.empty() && !q2.empty()){
- q1.push(-q2.top());
- q2.pop();
- }
- while (-q1.top()<=q2.top() && !q1.empty() && !q2.empty()){
- q2.push(-q1.top());
- q1.pop();
- }
- while (sz(q1)-sz(q2)>=1 && !q1.empty() && !q2.empty()){
- q2.push(-q1.top());
- q1.pop();
- }
- while (sz(q2)-sz(q1)>=1 && !q1.empty() && !q2.empty()){
- q1.push(-q2.top());
- q2.pop();
- }
- if ((sz(q1)+sz(q2))&1){
- if (sz(q1)>sz(q2)) cout<<-q1.top();
- else cout<<q2.top();
- cout<<endl;
- }else cout<<(q2.top()-q1.top())/2<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment