Josif_tepe

Untitled

Dec 11th, 2025
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     cin >> n;
  8.    
  9.     int a[n];
  10.     for(int i = 0; i < n; i++) {
  11.         cin >> a[i];
  12.     }
  13.    
  14.     sort(a, a + n);
  15.    
  16.     int x = 10;
  17.     int L = 0, R = n - 1;
  18.    
  19.     while(L <= R) {
  20.         int middle = (L + R) / 2;
  21.         if(x == a[middle]) {
  22.             cout << "YES!" << endl;
  23.             break;
  24.         }
  25.        
  26.         if(x < a[middle]) {
  27.             R = middle - 1;
  28.         }
  29.         else {
  30.             L = middle + 1;
  31.         }
  32.     }
  33.    
  34.     return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment