monito2207

Untitled

Oct 11th, 2022
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7. const int MAX_SIZE = 1000000;
  8.  
  9. int main() {
  10.     int N, temp, Ivancho = 1;
  11.     int arr[MAX_SIZE];
  12.     cin >> N;
  13.     for (int i = 0; i < N; i++) {
  14.         cin >> arr[i];
  15.     }
  16.  
  17.     sort(arr, arr + N);
  18.     bool hasOne = false;
  19.     for (int i = 1; i <= N; i++) {
  20.         if (arr[i - 1] == 1)
  21.         {
  22.             hasOne = true;
  23.         }
  24.         if (arr[i - 1] > 0 && arr[i] - arr[i - 1] > 1) {
  25.             Ivancho = arr[i - 1] + 1;
  26.             break;
  27.         }
  28.         else if (arr[i - 1] > 0 && i == N)
  29.         {
  30.             Ivancho = arr[i - 1] + 1;
  31.             break;
  32.         }
  33.     }
  34.    
  35.     if (hasOne == false)
  36.     {
  37.         Ivancho = 1;
  38.     }
  39.     cout << Ivancho;
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment