Professional Documents
Culture Documents
Running Median
Running Median
cout.precision(1);
int n; cin >> n;
double first; cin >> first;
cout << fixed << first << "\n";
double second; cin >> second;
cout << (first + second) / 2 << "\n";
priority_queue<double> max_heap;
priority_queue<double, vector<double>, greater<double>> min_heap;
if (first >= second) {
min_heap.push(first);
max_heap.push(second);
} else {
min_heap.push(second);
max_heap.push(first);
}
for (int i = 0; i < n - 2; ++i) {
double elem; cin >> elem;
if (elem > max_heap.top())
min_heap.push(elem);
else
max_heap.push(elem);