summaryrefslogtreecommitdiffstats
path: root/šola/aps1/dn/mediane/resitev.cpp
blob: 32e673330be70d96e4260933a37ca7486baddc3a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <queue>
using namespace std;
int main (void) {
	long N, m;
	cin >> N;
	priority_queue<long> l;
	priority_queue<long> d;
	for (long i = 0; i < N; i++) {
		long r;
		cin >> r;
		if (i == 0) {
			m = r;
		} else if (r > m) {
			d.push(-r);
			l.push(m);
		} else {
			l.push(r);
			d.push(-m);
		}
		if (d.size() > l.size()) {
			m = -d.top();
			d.pop();
		} else if (l.size() > 0) {
			m = l.top();
			l.pop();
		}
		cout << m << endl;
	}
}