Advertisement
pb_jiang

CF271C

Oct 5th, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <assert.h>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
  5. template <typename... Args> void logger(string vars, Args &&... values)
  6. {
  7.     cerr << vars << " = ";
  8.     string delim = "";
  9.     (..., (cerr << delim << values, delim = ", "));
  10.     cerr << endl;
  11. }
  12.  
  13. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  14. using ll = long long;
  15. using pii = pair<int, int>;
  16.  
  17. int n;
  18. ll a[300003];
  19. ll v[300003];
  20.  
  21. int main(int argc, char **argv)
  22. {
  23.     scanf("%d", &n);
  24.     for (int i = 1; i <= n; ++i) {
  25.         scanf("%lld", a + i);
  26.         if (a[i] < 300003) {
  27.             v[a[i]] = 1;
  28.         }
  29.     }
  30.     for (int i = 0; i < 300003; ++i)
  31.         v[i + 1] += v[i];
  32.     int lb = 0, ub = 300003, cnt = ub - lb, step, it;
  33.     while (cnt) {
  34.         it = lb, step = cnt / 2, it += step;
  35.         if (it < v[it] + (n - v[it]) / 2) {
  36.             lb = it + 1;
  37.             cnt -= step + 1;
  38.         } else {
  39.             cnt = step;
  40.         }
  41.     }
  42.     if (v[lb + 1] + (n - v[lb + 1]) / 2 >= lb + 1)
  43.         lb++;
  44.     printf("%d\n", lb);
  45.     return 0;
  46. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement