Advertisement
kdzhr

Untitled

Jan 5th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. // WA 3 1306 Timus test
  2.  
  3. # include <iostream>
  4. # include <set>
  5. # include <algorithm>
  6. # include <iomanip>
  7.  
  8. using namespace std;
  9.  
  10. int main() {
  11.     int32_t n;
  12.     int32_t cur_n = 0;
  13.     set<int32_t> m;
  14.     cin >> n;
  15.     for (size_t i = 0; i < n; i++) {
  16.         int32_t a;
  17.         cin >> a;
  18.         m.insert(a);
  19.         cur_n++;
  20.         if (cur_n > 150000) {
  21.             m.erase(m.begin());
  22.             m.erase(m.rbegin());
  23.             cur_n -= 2;
  24.         }
  25.     }
  26.  
  27.     if (cur_n % 2 == 0) {
  28.         auto it1 = m.begin();
  29.         advance(it1, cur_n / 2 - 1);
  30.         auto it2 = m.begin();
  31.         advance(it2, cur_n / 2);
  32.         int64_t res = (int64_t)*it1 + (int64_t)*it2;
  33.         cout << fixed << setprecision(1) << (double)res / 2.0;
  34.     }
  35.     else {
  36.         auto it1 = m.begin();
  37.         advance(it1, cur_n / 2);
  38.         cout << *it1;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement