Advertisement
NikolayChukanov

lec-A[18]

Mar 27th, 2023
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define all(x) x.begin(), x.end()
  6.  
  7. int mex(vector<int> a) {
  8.     int n = a.size();
  9.     sort(all(a));
  10.     if (a[0] > 0) {
  11.         return 0;
  12.     }
  13.     for (int i = 0; i < n - 1; ++i){
  14.         if (a[i] + 1 < a[i + 1]){
  15.             return a[i] + 1;
  16.         }
  17.     }
  18.     return a.back() + 1;
  19. }
  20.  
  21. int main() {
  22.     int n;
  23.     cin >> n;
  24.     vector<int> a(n);
  25.     for (int i = 0; i < n; ++i){
  26.         cin >> a[i];
  27.     }
  28.     cout << mex(a) << endl;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement