ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1306. Sequence Median

I've tried everything but still MLE
Posted by achvanov 30 Mar 2019 12:36
I've tried priority_queue and heap, but still MLE. Here's my code, can somebody help me?
#include <iostream>
#include <algorithm>
#include <vector>
int main() {
int n, a;
std::cin >> n;
std::vector<int> v(n / 2 + 1);
for (int i = 0; i < n / 2 + 1; ++i) {
std::cin >> v[i];
}
std::make_heap(v.begin(), v.end());
for (int i = 0; i < (n + 1) / 2 - 1; ++i) {
std::cin >> a;
v.push_back(a);
std::push_heap(v.begin(), v.end());
std::pop_heap(v.begin(), v.end());
v.pop_back();
}
std::sort_heap(v.begin(), v.end());
if (n % 2) {
std::cout << v.back() << ".0";
}
else {
a = v.back();
v.pop_back();
std::cout << (0ll + a + v.back()) / 2 << '.';
if ((0ll + a + v.back()) % 2) {
std::cout << 5;
}
else {
std::cout << 0;
}
}

return 0;
}