Advertisement
pb_jiang

cf271c wa

Oct 5th, 2022
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 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.  
  20. int main(int argc, char **argv)
  21. {
  22.     scanf("%d", &n);
  23.     for (int i = 1; i <= n; ++i)
  24.         scanf("%lld", a + i);
  25.  
  26.     sort(a + 1, a + 1 + n);
  27.     int ans = 0;
  28.     int expect = 1;
  29.  
  30.     for (int lb = 1, ub = n; lb <= ub; ++lb) {
  31.         if (a[lb] == expect) {
  32.             ++expect;
  33.             ++ans;
  34.         } else {
  35.             while (lb + 1 <= ub) {
  36.                 ub -= 2;
  37.                 ++expect;
  38.                 ++ans;
  39.                 if (lb <= ub && a[lb] == expect) {
  40.                     ++expect;
  41.                     ++ans;
  42.                     break;
  43.                 }
  44.             }
  45.         }
  46.     }
  47.  
  48.     printf("%d\n", ans);
  49.     return 0;
  50. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement