0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-05 02:06:27 +00:00
OI-codes/Luogu/problem/P1168/P1168.cpp
2021-01-02 15:30:52 +08:00

33 lines
680 B
C++

#include<bits/stdc++.h>
using namespace std;
int main() {
int n, a[100005], k;
priority_queue<int, vector<int>, less<int> > s;
priority_queue<int, vector<int>, greater<int> > l;
cin >> n;
for(int i = 1 ; i <= n ; i++) {
cin >> a[i];
k = i/2+1;
if(!l.empty() && a[i] >= l.top()) {
s.push(a[i]);
}
else {
l.push(a[i]);
}
while(l.size() < k) {
l.push(s.top());
s.pop();
}
while(s.size() < k) {
s.push(l.top());
l.pop();
}
if(i%2) {
cout << s.top() << endl;
}
}
return 0;
}