summaryrefslogtreecommitdiffstats
path: root/šola/aps1/dn/mediane/resitev.cpp
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2024-11-18 00:18:24 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2024-11-18 00:18:24 +0100
commit5ddc2e50dcfe5a1e36bb5a04008e29a33a661921 (patch)
tree50d520ad03f3f267aa7f6504c6e15d9106b97ae6 /šola/aps1/dn/mediane/resitev.cpp
parentaps1dn2: zlivanje (diff)
downloadr-5ddc2e50dcfe5a1e36bb5a04008e29a33a661921.tar
r-5ddc2e50dcfe5a1e36bb5a04008e29a33a661921.tar.gz
r-5ddc2e50dcfe5a1e36bb5a04008e29a33a661921.tar.bz2
r-5ddc2e50dcfe5a1e36bb5a04008e29a33a661921.tar.lz
r-5ddc2e50dcfe5a1e36bb5a04008e29a33a661921.tar.xz
r-5ddc2e50dcfe5a1e36bb5a04008e29a33a661921.tar.zst
r-5ddc2e50dcfe5a1e36bb5a04008e29a33a661921.zip
Diffstat (limited to 'šola/aps1/dn/mediane/resitev.cpp')
-rw-r--r--šola/aps1/dn/mediane/resitev.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/šola/aps1/dn/mediane/resitev.cpp b/šola/aps1/dn/mediane/resitev.cpp
new file mode 100644
index 0000000..32e6733
--- /dev/null
+++ b/šola/aps1/dn/mediane/resitev.cpp
@@ -0,0 +1,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;
+ }
+}