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\n",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\n",small.top());
23     }
24     return 0;
25 }

 

相关文章:

  • 2021-12-24
  • 2021-11-11
  • 2021-10-13
  • 2021-05-13
  • 2021-05-24
  • 2021-09-20
  • 2022-12-23
猜你喜欢
  • 2022-01-16
  • 2021-12-03
  • 2022-12-23
  • 2021-11-11
  • 2022-12-23
  • 2021-09-04
相关资源
相似解决方案