1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 using namespace std; 5 priority_queue<int> big;//大根堆 6 priority_queue< int,vector<int>,greater<int> >small;//小根堆 7 int n,cnt=1,x; 8 int main() 9 { 10 scanf("%d",&n); 11 scanf("%d",&x); 12 small.push(x); 13 printf("%d ",x); 14 while(--n) 15 { 16 scanf("%d",&x); 17 if(x>=small.top()) small.push(x); 18 else big.push(x); 19 ++cnt; 20 while((int)(small.size()-big.size())>1) big.push(small.top()),small.pop();//size返回类型为unsigned int! 21 while(big.size()>small.size()) small.push(big.top()),big.pop(); 22 if(cnt&1) printf("%d ",small.top()); 23 } 24 return 0; 25 }