You are on page 1of 1

int main(){

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);

if (i % 2 == 1 && max_heap.size() > min_heap.size()) {


min_heap.push(max_heap.top());
max_heap.pop();
} else if (i % 2 == 1 && max_heap.size() < min_heap.size()) {
max_heap.push(min_heap.top());
min_heap.pop();
}

if (max_heap.size() > min_heap.size())


cout << max_heap.top() << "\n";
else if (max_heap.size() < min_heap.size())
cout << min_heap.top()<< "\n";
else if (max_heap.size() == min_heap.size())
cout << (max_heap.top() + min_heap.top()) / 2 << "\n";
}
return 0;
}

You might also like