0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-25 19:12:02 +00:00
OI-codes/Luogu/P1168/P1168.cpp

32 lines
682 B
C++
Raw Normal View History

2021-11-19 09:01:13 +00:00
#include <bits/stdc++.h>
2020-11-07 13:08:59 +00:00
using namespace std;
int main() {
2020-11-07 15:47:19 +00:00
int n, a[100005], k;
priority_queue<int, vector<int>, less<int> > s;
priority_queue<int, vector<int>, greater<int> > l;
2020-11-07 13:08:59 +00:00
cin >> n;
2021-11-19 09:01:13 +00:00
for (int i = 1; i <= n; i++) {
2020-11-07 15:47:19 +00:00
cin >> a[i];
2021-11-19 09:01:13 +00:00
k = i / 2 + 1;
if (!l.empty() && a[i] >= l.top()) {
2020-11-07 15:47:19 +00:00
s.push(a[i]);
2021-11-19 09:01:13 +00:00
} else {
2020-11-07 15:47:19 +00:00
l.push(a[i]);
}
2021-11-19 09:01:13 +00:00
while (l.size() < k) {
2020-11-07 15:47:19 +00:00
l.push(s.top());
s.pop();
}
2021-11-19 09:01:13 +00:00
while (s.size() < k) {
2020-11-07 15:47:19 +00:00
s.push(l.top());
l.pop();
}
2021-11-19 09:01:13 +00:00
if (i % 2) {
2020-11-07 15:47:19 +00:00
cout << s.top() << endl;
2020-11-07 13:08:59 +00:00
}
}
return 0;
}